开发者

stopping on the last frame (flash)

I want my movieclip to play once and stop on the last frame. I use the following code in the loop of my movieclip class. (this is as3)

if(currentFrame == 120)
stop();

120 is the last frame. It plays 开发者_StackOverflow社区once. but the problem is it goes back to frame 1 again. is there a better method of stopping a movieclip on a particular frame.


If you want to do it with actionscript and not add a stop() to the last frame on the timeline manually, then you can use the undocumented addFrameScript() method.

mc.addFrameScript(mc.totalFrames - 1, function():void 
{
    mc.stop();
});

Can't remember the scope of the function, but you can either use mc.stop(), or just stop().

*EDIT - Added -1 to the first parameter of addFrameScript, because it is zero based (so to put a frameScript on frame 10 you would put 9).


On the timeline, you can just put a keyframe at the end, and add the stop(); method there. When it reaches that frame, the stop(); method will execute, and the clip will stop.

Assuming you are using the timeline that is, but sounds like you are.


Easiest way:

  1. Just select the last Frame in the timeline. Open the Actions pane(F8). Ensure the frame u selected is still selected, if not then select again while the Actions pane is open.
  2. After selecting, just add the simple stop() function in the the 'Action-Frame' pane.

    //add the following line to the actions pane of the last frame.
    stop();
    
  3. You're done. You can optionally add a replay button if needed.


This seems more along the lines of what you're looking for:

addEventListener(Event.ENTER_FRAME, function(e:Event){
    if(currentFrame == totalFrames){
      stop();
      removeEventListener(event.type, arguments.callee);
    }
});

I added an event listener (for Actionscript 3) so on every frame this function will fire and check what frame it is on. If it's the last frame it will stop. Based on your example I'm presuming you have a class that's extending MovieClip.

0

上一篇:

下一篇:

精彩评论

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

最新问答

问答排行榜