开发者

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

开发者 https://www.devze.com 2023-02-25 13:06 出处:网络
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.

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


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;
    }
}
0

精彩评论

暂无评论...
验证码 换一张
取 消