ENTER_FRAME & EXIT_FRAME triggers multiple events for singe frame


#1

If I have an MovieClip that is playing and have an event listener for either ENTER_FRAME or EXIT_FRAME, the listener function will be called at least two times, sometimes more, for each frame in the clip. In the following example the var counter should count the same as movieClip.currentFrame but counter is 2 sometimes 3 times movieClip.currentFrame.

counter = 0;
movieClip.addEventListener(Event.ENTER_FRAME, trackPlay);
movieClip.gotoAndPlay(1);

function trackPlay(event:Event)
{
counter++;
trace(counter+","+movieClip.currentFrame);
if (movieClip.currentFrame == movieClip.totalFrames) {
movieClip.removeEventListener(Event.ENTER_FRAME, trackPlay);
movieClip.gotoAndStop(1);
}


#2

Is this a SWF file?

Unless we accidentally dispatch ENTER_FRAME multiple times on the same render frame, the idea is that OpenFL supports variable frame rates between the host application and the SWF animation.

Let’s say the SWF has a frame-rate of 12 FPS, but you’re using full speed on a 144Hz HTML5 window.

The default Flash Player behavior would be to play your animation 12x faster than normal, but our default behavior is to play it still at the same speed (but fire ENTER_FRAME approximately 12 times per frame of the MovieClip).

The define is currently swf-parent-fps if you want to force the same behavior as Flash Player, where animation syncs with the parent FPS no matter what, so try openfl test html5 -Dswf-parent-fps or <define name="swf-parent-fps" /> in XML