Francis
Francis

Reputation: 45

Flash: Play a movieclip then go to a different frame for each buttons

I have 10 buttons on my homepage and I want to play the same movieclip when you click on a button and after that move to a specific frame for each different button.

Someone know an easy to make this without having to create 10 differents movieclips just to change the action at the end of the movieclip?

Thank you

Upvotes: 1

Views: 730

Answers (1)

Mattias
Mattias

Reputation: 3907

This is a fairly easy way of doing it: Make sure your buttons is present in the timeline when the script executes.

button1.addEventListener(MouseEvent.CLICK, onClickHandler);
button2.addEventListener(MouseEvent.CLICK, onClickHandler);
button3.addEventListener(MouseEvent.CLICK, onClickHandler);

private function onClickHandler(event : MouseEvent) : void
{
    switch(event.target)
    {
        case button1:
            // code to execute when button 1 is clicked
            gotoAndPlay(50);
            break;

        case button2:
            // code to execute when button 2 is clicked
            gotoAndPlay(100);
            break;

        case button3:
            // code to execute when button 3 is clicked
            gotoAndPlay(150);
            break;
    }
}

Upvotes: 1

Related Questions