Actionscript – Action Script 3 : Hover over button to play a movie clip

actionscriptactionscript-3flashflash-cs5

I have a button on the main time line. When I hover over the button, I want a movie clip to play. When the movie clip is over, I would like for it to go to the next frame. Is this possible?

Best Answer

Yes that is possible, here is an example:

import fl.controls.Button;
import flash.events.MouseEvent;

var hover:Button = new Button();
hover.label = "Hover";
addChild(hover);
hover.x = 100;
hover.y = 100;
var mc:MovieClip = new MovieClip();
addChild(mc);
mc.x = 300;
mc.y = 300;

hover.addEventListener(MouseEvent.MOUSE_OVER, onMouseOver);
 
function onMouseOver(e:MouseEvent):void
{
    if(mc.currentFrame < mc.totalFrames) {
         mc.play();
    } else {
         gotoAndStop(currentFrame + 1);
    }
}

Here's a helpful article on the subject: AS3 Mouse Events and Mouse Related User Actions

Related Topic