Is AS3 Event.ENTER_FRAME always executed on every frame? Even on slow computers?

I have a script that relies on the ENTER_FRAME event to fire every time. I noticed that on some slower computers there may be some lag when playing a flash movie.

Does ENTER_FRAME on every frame, even if it is on a slow computer? If the flash movie is delayed, is the ENTER_FRAME event ENTER_FRAME and the rendering is just trying to catch up?

Does ENTER_FRAME code ENTER_FRAME reliable way to execute code every time I enter a frame?

+4
source share
4 answers

Yeah. Each frame, no exceptions. If something slows the movie down (either heavy scripts or heavy graphics), the Event.ENTER_FRAME handlers are still executed before the frame is rendered.

Therefore, it is generally recommended that you use a Timer instance with TimerEvent.TIMER , even if its delay is set to the β€œideal” frame duration for your fps movie. Because the Timer handler is not that should be started at exactly the same speed.

See the following link for a more detailed explanation: Elastic Racecourse

+6
source

if you have set the frame rate to 30 frames per second, then the event will fire 30 times per second if you do not load the processor, reducing the frame rate. Therefore, if the frame rate fluctuates, you can get more consistent results with a timer event.

on a note, keep in mind that ... Using many event handlers can also create performance problems (if there are too many) Each time it is called, flash must create an event object, at least. This means that you have a memory that needs to be allocated every time an event fires. This memory then needs to be garbage collected, and garbage collection will also use resources to execute.

If you have many video clips or sprites, it may be advisable to have one controller that controls all of them, and not everyone who has their own EnterFrame handler.

+1
source

A general answer to a general question.

If you want to improve Flash Player performance, consider the following points.

  • Do not use strokes if necessary. (Strokes more cpu
    intensive)

  • Use smaller gradient colors if possible.

  • Use optimized bitmaps, if any.

  • Effectively use addChild(yourObject) , addChildAt(yourObject, index) , removeChild(yourObject) , removeChildAt(index) .

  • Listen to Event.ADDED_TO_STAGE and Event.REMOVED_FROM_STAGE respectively.

  • Listen to addEventListener(somelistener, somefunction);
    removeEventListener (somelistener, somefunction);

  • Listen to Event.ACTIVATE and Event.DEACTIVATE.

  • If objects are being loaded externally, make sure you use unloadAndStop() to completely remove unnecessary objects from the stage.

+1
source

Check it out for those who are looking for a solution independent of the frame rate ... this guy is very smart and has the technique for sequentially animating multiple frames (slower devices, desktop computers, etc.) and saving the frame rate of your object regardless of your time scales, check here . Tips 4 and 5. Hope this helps!

I found that the timer class is actually very incompatible when mashing the buttons, sometimes the timer just does not end the cycle, and the TIMER.COMPLETE event is never reached if I had 5 cycles in 100 ms, it just stopped after 3 cycles .. In addition, the frame rate is triggered every frame, but DO NOT FULL !!! If you have a lag behind the CPU, your frame rate will decrease, and therefore, you will not update anything at regular intervals, but rather, regardless of the current frame rate. Check out this link, there is even some frame rate code that you can use in your projects to check this out.

0
source

All Articles