Skip to main content
Participating Frequently
May 27, 2013
Answered

trigger animation on mouseover of a segment only

  • May 27, 2013
  • 1 reply
  • 1300 views

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!

This topic has been closed for replies.
Correct answer Ned Murphy

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.

1 reply

Ned Murphy
Legend
May 27, 2013

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);

     }

}

Participating Frequently
May 27, 2013

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

Ned Murphy
Ned MurphyCorrect answer
Legend
May 27, 2013

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.