开发者

how to make a button go to a specific frame on the main timeline

how to make a button go to a specific frame on the main timeline my button called a play_btn and i wa开发者_高级运维nt it to go to a specific frame on the main timeline ???


put this code on frame 1 of your main timeline, in the same scene as the button.

play_btn.addEventListener(MouseEvent.CLICK, play_btnClickHandler);

function play_btnClickHandler(ev:MouseEvent):void
{
    //The actual code to jump to a specific frame
    this.gotoAndPlay(30);
}

30 being your frame number.

'this.' can be omitted, but I like it as it ensures its easier to understand what is being affected to those of whom are reading your code and may not be aware completely of what's going on.


it's often better to use a frame label in case the frame number changes following a modification in your animation.

play_btn.addEventListener(MouseEvent.CLICK, play_btnClickHandler);

function play_btnClickHandler(ev:MouseEvent):void
{
    //The actual code to jump to a specific frame
    this.gotoAndPlay('myFrameLabel');
}
0

上一篇:

下一篇:

精彩评论

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

最新问答

问答排行榜