So i have a simple button implemented via an MC. I have event handlers registered for the MOUSE_OUT and MOUSE_OVER events such that a little animation plays when the mouse hovers over and when the mouse exits my button. My initial problem was that the MOUSE_OUT event would sometimes fail to fire, leaving the MC in the MOUSE_OVER state. I did some searching and found that you could look at the target.toString of the event, and if the current target isn’t the MC then play the same frames from the MC as you would on MOUSE_OUT. This solved the MOUSE_OUT failed to fire problem, but caused a new one. Now my MOUSE_OVER animation doesn’t play properly, it just skips to the last frame. It looks to me that my code to check for if the current target has changed is firing before my MOUSE_OVER animation has completed, causing it to skip to its end prematurely. Anyhow, here’s my code so far:
addEventListener(MouseEvent.MOUSE_OUT, myMouseOut);
addEventListener(MouseEvent.MOUSE_OVER, myMouseOver);
function myMouseOver(event:MouseEvent):void {
gotoAndPlay(2);
if (event.target.toString() != "TABBUTTON_MC_1)"){
gotoAndPlay(21);
}
}
function myMouseOut(event:MouseEvent):void {
gotoAndPlay(21);
}
After a little more careful observation I’ve noticed that this seems to only happen if the mouse is moved out from over the MC before the MOUSE_OVER animation is done. I’m also noticing that enjoyable “infinite replay” effect where if you hover the mouse on the very edge of the hit zone for the MC it continuously fires off the over and out events, leaving the MC at the end of the over state if you move the mouse away.