Flex web application: prevent frame rates from dropping when the window is invisible

Thus, a new “function” appeared in the flash player from version 10.1, which reduces the player's frame rate to 2 frames per second when the application window leaves the field of view. This is good news for performance, but it may break some features, such as the Timer class.

I have an application that uses a timer to display a countdown. Given the nature of the application, the timer must complete its countdown, even if the user does not see it. Imagine that you need to give the user only 10 seconds to complete the task. If the user minimizes the window halfway through the counter, they can take as much time as they want, and they will have 5 seconds left when they return to the window. This, apparently, can not be avoided with the help of new flash-players.

Air applications have a backgroundFrameRate property that can be set to prevent this behavior, but it is part of the WindowedApplication class, so it seems to be unavailable in a web application. Does anyone know a way to maintain a constant frame rate, even if the window is not visible? Thanks

+5
source share
3 answers

Setting the built-in swf wmode parameter to opaque will prevent frame rate throttling.

Brian

+1
source

I have not tried myself, but maybe you can try to make the frame rate turn off:

stage.addEventListener(Event.DEACTIVATE, onDeactivate); 

function onDeactivate (e:Event):void 
{ 
    //eg myFrameRate=24
    stage.frameRate = myFrameRate; 
} 

Let me know if this works.

0
source

:

private var numer:int = 0;
private var prevNumer:int = 0;
private var timer:Timer = new Timer( 1000, 0 )

[...]

var tf:TextField = new TextField ();
addChild (tf);
addEventListener ( Event.ENTER_FRAME, onEnterFrame )
timer.addEventListener (TimerEvent.TIMER, onTimer )
timer.start()
function onTimer ( e:TimerEvent ):void
{ tf.appendText (' ' + (numer - prevNumer)); prevNumer = numer;}
function onEnterFrame ( e:Event ):void { numer++ }

, , , tf , FPS. FPS, . , , 2 2 2 2 2, FPS 2.

onDeactivate AsTheWormTurns . , fps . wmode = -

- , : onEnterFrame FPS:

function onEnterFrame ( e:Event ):void { numer++; stage.frameRate = 30 }

Obviously, you cannot install FPS when the flash is not visible! Well, you cannot install FPS unless you set it to 1.

The workaround to your problem is simple, just create another timer similar to the one above, but with an additional conditional:

function onTimer ( e:TimerEvent ):void {
if ( numer - prevNumer == 2 ) adjustOriginalTimer();
tf.appendText (' ' + (numer - prevNumer)); prevNumer = numer;
}

E: You can read about it here: http://help.adobe.com/en_US/as3/mobile/WS4bebcd66a74275c36cfb8137124318eebc6-8000.html

0
source

All Articles