stopping on the last frame (flash)

安稳与你 提交于 2020-01-10 02:59:32

问题


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 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.


回答1:


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).




回答2:


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.




回答3:


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.




回答4:


it was because the object was getting called twice.




回答5:


from messing around wit it, I know the problem has nothing to do with flash not responding to my stop() function. I believe it may have something to do with flash calling the movieclip twice. One on top of another. Making it look like it started over again. I am not sure. If I call the movieclip anywhere else, it works. just not in my loop. I did do a trace and the trace only showed up once which shows it initiated it once.




回答6:


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.




回答7:


I figured it out. Honestly, I think my application is flawed. It worked miraculously and I didnt do anything. In my loop i did the if(currentframe == totalframes) and what didnt happen before is now happening perfectly. I dont know why. But like I said, it may be a software issue because I sometimes have issues passing values through contructors. And have to create special methods to accepts those values.



来源:https://stackoverflow.com/questions/2099049/stopping-on-the-last-frame-flash

易学教程内所有资源均来自网络或用户发布的内容,如有违反法律规定的内容欢迎反馈
该文章没有解决你所遇到的问题?点击提问,说说你的问题,让更多的人一起探讨吧!