PDA

View Full Version : Button AS3 Help



broome
April 15th, 2009, 04:21 AM
I have an MC "homeBtn" that I'm using as an animated button.
The "homeBtn" is made of 2 mirroring MC's named "topMC" and "bottomMC" since they mirror and function the same I will be addressing only the "topMC"
Inside "topMC" is the animation named "liquidMC"
These are all MC properties.
Below is the AS3 Code. Works well but when the mouse scrolls out the animation is stuck ie stops animating and not going back to frame 1, I know there is a code to make it turn off, just haven't figured it out yet and am looking for help.
//////////////////////////////////////////////
import flash.events.MouseEvent;
stop();

homeBtn.topMC.addEventListener(MouseEvent.MOUSE_OV ER, on_rollOverH);
homeBtn.topMC.addEventListener(MouseEvent.MOUSE_OU T, on_rollOut);
homeBtn.topMC.addEventListener(MouseEvent.CLICK, goHome);

function goHome(e:MouseEvent):void {
gotoAndStop ("home");
}

function on_rollOverH(e:Event):void {
homeBtn.topMC.liquidMC.play();
homeBtn.bottomMC.liquidMC.play();
homeBtn.topMC.play();
homeBtn.bottomMC.play();
}
function on_rollOut(e:Event):void {
homeBtn.topMC.liquidMC.stop(); //doesn't work smoothly
homeBtn.bottomMC.liquidMC.stop(); //doesn't work smoothly
homeBtn.topMC.stop(); //doesn't work smoothly
homeBtn.bottomMC.stop(); //doesn't work smoothly
}


Below is the AS2 I am having problems with in coding in AS3
///////////////////////////////////////////////

this.topMC.onRollOver = function() {
buttonOver = true;
};
this.topMC.onRollOut = bottomMC.onDragOut = function () {
buttonOver = false;
};
this.onEnterFrame = function() {
if (buttonOver) {
this.topMC.liquidMC.play();
this.bottomMC.liquidMC.play();
this.topMC.play();
this.bottomMC.play();
buttonOver = false;
}
};
stop();
///////////////////////////////
ANY help would rock my day :sen:
Thanks
Jer

DFdou
April 15th, 2009, 05:53 AM
it's seemed that you should use prevFrame();
some code example:
btn.addEventListener ( Event.ENTER_FRAME, btn_enter );
btn.addEventListener ( MouseEvent.ROLL_OVER, btn_over );
btn.addEventListener ( MouseEvent.ROLL_OUT, btn_out );
function btn_over (_evt:MouseEvent):void {
_evt.target.over = true;
}
function btn_out (_evt:MouseEvent):void {
_evt.target.over = false;
}
function btn_enter (_evt:Event):void {
var _mc = _evt.target;
if ( _mc.over == true ) {
_mc.nextFrame ();
} else {
_mc.prevFrame ();
}
}
when rollover then btn.nextFrame ();,else btn.prevFrame();