Marci-man
Marci-man

Reputation: 2233

how to play next x frames or previous x frames with a click of a button in Flash Professional CS6(AS3)

I have to design a simply animation which should play next X frames with the click of forward button and previous X frames (in reverse order) with the click of backward button. I have extensive experience in AS3 but i just don't seem to get where to start in Flash Professional.

I have managed to get a button on the screen and some animation, I get the right trace when the button is clicked but I don't get any further...

thanks for any help

cheers

Upvotes: 0

Views: 3180

Answers (1)

Adam Harte
Adam Harte

Reputation: 10510

You can try having a ticker variable that counts the frames to play. Just set this var on your button clicks. Then use an enterframe handler to go to the correct frame each frame. Example:

var maxFramesToPlay:int = 20;
var framesToPlay:int = 0;

addEventListener(Event.ENTER_FRAME, enterFrameHandler);
forwardButton.addEventListener(MouseEvent.CLICK, forwardClickHandler);
backButton.addEventListener(MouseEvent.CLICK, backClickHandler);

private function forwardClickHandler(e:MouseEvent):void 
{
    framesToPlay = maxFramesToPlay;
}

private function backClickHandler(e:MouseEvent):void 
{
    framesToPlay = -maxFramesToPlay;
}

private function enterFrameHandler(e:Event):void 
{
    if (framesToPlay > 0) 
    {
        MovieClip(this).nextFrame();
        framesToPlay--;
    }
    else if (framesToPlay < 0) 
    {
        MovieClip(this).prevFrame();
        framesToPlay++;
    }
    else 
    {
        // framesToPlay is zero, so don't do anything.
    }
}

You can put this functionality into a class that extends MovieClip, then in Flash just set it as the Document Class.

Upvotes: 2

Related Questions