5

So there's been a new "feature" in the flash player since version 10.1, which reduces the player's framerate to 2 fps when the application window is out of view. This is good news for performance, but it can break some functionality, such as the Timer class.

I have an application which uses a Timer to display a countdown. Given the nature of the application, it is required for the Timer to complete its countdown even if the user is not there to see it. Imagine that you need to give the user only 10 seconds to perform a task. If the user minimizes the window halfway through the counter, they can take as much time as they want and still have 5 seconds left when they return to the window. This apparently can not be avoided with the newer flash players.

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

JayPea
  • 9,551
  • 7
  • 44
  • 65
  • +1 for adding the comment about the property in an AIR App. I was unaware that existed. I'd be equally surprised it there was a way to do this in a browser. – JeffryHouser Nov 26 '11 at 06:07
  • Not yet, sorry. I've been extremely busy but I'll post what I've found as soon as I try it out. I did run some quick tests and I had a hard time replicating the delay, which leads me to believe that perhaps I was wrong about the framerate drop affecting the timer. Either way I'll try to test it although I'm not sure how to measure the framerate with the window out view (in case the timer is not affected). I thought the bounty would be given automatically to the answer with the highest score, but if it's not the case I can accept your answer since you were the first one to reply. – JayPea Dec 06 '11 at 17:29

3 Answers3

1

Setting the wmode parameter of the embedded swf to opaque will prevent the framerate throttling.

Brian

Drenai
  • 11,315
  • 9
  • 48
  • 82
0

I've not tried myself, but maybe you can try to force the framerate onDeactivate:

stage.addEventListener(Event.DEACTIVATE, onDeactivate); 

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

Let me know if this works.

AsTheWormTurns
  • 1,318
  • 3
  • 13
  • 26
0

Testing with:

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++ }

shows clearly, that when You see the flash, tf appends numbers equal to Your FPS. If timer would get changed together with FPS, You wouldn't see a difference when minimizing a window. But, coming back You see 2 2 2 2 2, that is, FPS dropped to 2.

onDeactivate solution by AsTheWormTurns doesn't work. Event is fired, but fps not changed. wmode=opaque solution by Mr Brian Bishop doesn't work too

something obvious to try: change onEnterFrame function to set FPS:

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

Obviously You can't set FPS when flash is not visible! Well, You can't set FPS unless You set it to 1.

Workaround to Your problem is simple, just make another timer similar to this above but with 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