Exit
  • Global community
    • Language:
      • Deutsch
      • English
      • Español
      • Français
      • Português
  • 日本語コミュニティ
  • 한국 커뮤니티
0

trigger animation on mouseover of a segment only

New Here ,
May 27, 2013 May 27, 2013

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!

TOPICS
ActionScript
1.2K
Translate
Report
Community guidelines
Be kind and respectful, give credit to the original source of content, and search for duplicates before posting. Learn more
community guidelines

correct answers 1 Correct answer

LEGEND , May 27, 2013 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.

Translate
LEGEND ,
May 27, 2013 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);

     }

}

Translate
Report
Community guidelines
Be kind and respectful, give credit to the original source of content, and search for duplicates before posting. Learn more
community guidelines
New Here ,
May 27, 2013 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

Translate
Report
Community guidelines
Be kind and respectful, give credit to the original source of content, and search for duplicates before posting. Learn more
community guidelines
LEGEND ,
May 27, 2013 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.

Translate
Report
Community guidelines
Be kind and respectful, give credit to the original source of content, and search for duplicates before posting. Learn more
community guidelines
New Here ,
May 29, 2013 May 29, 2013

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

Translate
Report
Community guidelines
Be kind and respectful, give credit to the original source of content, and search for duplicates before posting. Learn more
community guidelines
New Here ,
May 29, 2013 May 29, 2013

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?

Translate
Report
Community guidelines
Be kind and respectful, give credit to the original source of content, and search for duplicates before posting. Learn more
community guidelines
LEGEND ,
May 29, 2013 May 29, 2013

You should not need to.  YOu just need to be sure to have the same area instance extending from frame 1 to the end.

Translate
Report
Community guidelines
Be kind and respectful, give credit to the original source of content, and search for duplicates before posting. Learn more
community guidelines
New Here ,
May 29, 2013 May 29, 2013

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

Translate
Report
Community guidelines
Be kind and respectful, give credit to the original source of content, and search for duplicates before posting. Learn more
community guidelines
LEGEND ,
May 29, 2013 May 29, 2013
LATEST

You probably need to remove the ENTER_FRAME event listener on the rollover, though you have to check if it is assigned.

Translate
Report
Community guidelines
Be kind and respectful, give credit to the original source of content, and search for duplicates before posting. Learn more
community guidelines