Checking if animation has already happened in AS3.
In my project, I have an animation play on rollover, but I only want it to be able to happen once... So I want to disable the rollover code if it's already happened once (and have the mc that animated stay in it's finished state).
This is the code I currently have...
Code:
button_mc.addEventListener(MouseEvent.ROLL_OVER, manageMouseOver, false, 0, true);
function manageMouseOver(event:MouseEvent):void{
gotoAndPlay("2");
}
There are two ways to handle this:
1) You could just remove the event listener for the RollOver.
function manageMouseOver(event:MouseEvent):void{
gotoAndPlay("2");
button_mc.removeEventListener(MouseEvent.ROLL_OVER, manageMouseOver, false, 0, true);
}
2) You can create a variable and have a conditional statement
var isRolledOver:Boolean = false;
function manageMouseOver(event:MouseEvent):void{
if(isRolledOver==false){
gotoAndPlay("2");
}
isRolledOver = true;
}