Stop at last frame (flash)

I want my movieclip to play once and stop at 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. He plays once. but the problem is that it goes back to frame 1. is there a better way to stop the movie clip on a specific frame.

+6
flash actionscript-3
source share
7 answers

this happened because the object was called twice.

+1
source share

If you want to do this using ActionScript rather than adding stop () to the last frame in the timeline manually, you can use undocumented addFrameScript () .

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

It is not possible to remember the scope of a function, but you can either use mc.stop () or just stop ().

* EDIT - added -1 to the first addFrameScript parameter, because it is based on a zero value (therefore, put the frame code on frame 10 > you would put 9 ).

+12
source share

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

Assuming you are using a timeline that sounds like you are.

+3
source share

The easiest way:

  • Just select the last frame in the timeline. Open the Actions panel (F8). Make sure the selected frame u is selected if it is not selected, and then select again when the Actions panel is open.
  • Once selected, simply add the simple stop () function in the Action-Frame area.

     //add the following line to the actions pane of the last frame. stop(); 
  • You are done. If necessary, you can add a snooze button.

+3
source share

This is more like what you are 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 each frame this function will be launched and check which frame it is on. If this is the last frame, it will stop. Based on your example, I assume that you have a class extending MovieClip.

0
source share

from messing around wit it, I know that the problem has nothing to do with the flash not responding to my stop () function. I believe that this may have something to do with the flash call of the movie clip twice. One on top of the other. It looks like it started again. I'm not sure. If I call the movieclip anywhere else, it will work. just not in my loop. I made a trace, and the trace appeared only once, which shows that it initiated it once.

0
source share

I get it. Honestly, I believe that my application is flawed. He worked miraculously, and I did nothing. In my loop, I did if (currentframe == totalframes) and what didn't happen before now works fine. I do not know why. But, as I said, this can be a software problem, because I sometimes have problems passing values โ€‹โ€‹through constructors. And you need to create special methods to accept these values.

0
source share

All Articles