Copy link to clipboard
Copied
Hello all,
I am relatively new to flash and would very much appreciate the help of you veterans!
I am trying to figure out how to trigger an animation with onmouseover using only a specified SECTION of the image. Is this possible? Would it be best to apply the code to a single, top layer which only occupies a part of the overall image?
My second question is: is it also possible to have the animation run in reverse from whichever point it gets to with onmouseout?
THANKS FOR YOUR HELP!
Since the animation you mentioned is part of the same timeline that the code is in (not a separate animation) start by removing "animation." in the code I showed. Then just add a couple stop() commands once you see how things work after the removal.
Copy link to clipboard
Copied
If you want only a portion of an image, then create an invisible button or other object that you can assign a ROLL_OVER/ROLL_OUT event listener to. The event handler can just tell the animation to play() assuming it is a timeline animation.
To play a timeline animation in reverse you can use an ENTER_FRAME event listener and a prevFrame() command. Each time before you execute the prevFrame command you check if the animation has reached its first frame, and when it does you remove the ENTER_FRAME event listener.
areaName.addEventListener(MouseEvent.ROLL_OVER, startAnimation);
areaName.addEventListener(MouseEvent.ROLL_OUT, rewindAnimation);
function startAnimation(evt:MouseEvent):void {
animation.play();
}
function rewindAnimation(evt:MouseEvent):void {
stage.addEventListener(Event.ENTER_FRAME, reverseAnimation);
}
function reverseAnimation(evt:Event):void {
if(animationName.currentFrame > 1){
animation.prevFrame();
} else {
stage.removeEventListener(Event.ENTER_FRAME, reverseAnimation);
}
}
Copy link to clipboard
Copied
Hi Ned,
Thanks a million for your help. I added the code but am still a little stuck. Please forgive my inexperience. I have added the file here: http://www.neuverband.ch/temp/concerts.fla
I would be immensely grateful if you could take a look at it and tell me what I am doing wrong. You will see the button when you load it, but the mouseover effect does nothing. I think that I have mislabeled an instance somewhere but everything seems to be in order as far as I can tell. Flash is generally very intuitive but there are a few things which are really impossible to figure out on your own!
Best,
Paul
Copy link to clipboard
Copied
Since the animation you mentioned is part of the same timeline that the code is in (not a separate animation) start by removing "animation." in the code I showed. Then just add a couple stop() commands once you see how things work after the removal.
Copy link to clipboard
Copied
Hi Ned,
Once again, thanks (!!!)
My only remaining question is: if I do onmouseout the animation reverses from whichever point it has reached, however the onmouseover trigger is only active on the first frame. Should I add the relevant code to EVERY frame so that it restarts the animation from any given point (i.e if the mouse moves back and forth over the button quickly, before the animation has time to reverse all the way back to the beginning)?
I really appreciate your help, wish I could buy you a beer.
Best,
Paul
Copy link to clipboard
Copied
Maybe my last post wasn't clear enough - what I was asking was: do I need to add keyframes to every frame with the code and copy the same code which will re-trigger the forwards animation?
Copy link to clipboard
Copied
You should not need to. YOu just need to be sure to have the same area instance extending from frame 1 to the end.
Copy link to clipboard
Copied
Hmmm I thought that I had done that but it seems that the onmouseover is inactive until the animation has reversed all the way to the beginning. I have re-uploaded the .fla file here: http://www.neuverband.ch/temp/concerts.fla
Think you could take another look at it?
-Paul
Copy link to clipboard
Copied
You probably need to remove the ENTER_FRAME event listener on the rollover, though you have to check if it is assigned.
Find more inspiration, events, and resources on the new Adobe Community
Explore Now