Flashplayer Throttle : Solving a problem or creating one !

This might be a little late, but worth keeping an eye on. As we know since Flashplayer 10.1, the player is throttled in situations. What does that mean is the FlashPlayer will run the EnterFrame and Timer based events at much lower rates, when the player is not visible. Much lower means, as low as 2 FPS (2 frames per second) and AS2 Intervals as well as AS3 timers will low down to 2 events per second!!

This throttling is best for mobile and other devices which can run FlashPlayer now. Throttling means saving of energy and increasing battery life of the device. So it seems its the best thing happened to Flashplayer, while we are making content for the devices.

The problem arises when we create stuffs for desktops or laptops, where FlashPlayer was running since a long time, conventionally. And we still think we can go on developing our applications and games with the same mind set as we used to do till now. While developing games, the most used event is ENTER_FRAME and when throttling happens, all of the logic of the application/game goes wrong!! While the logic of the game still holds good if the player is active all the time but once the player is invisible, the player starts to throttle and frame-rates and timer events start to fall. This will happen even our game is running in a browser tab and we are in another tab. This can happen if we scroll down a page and the game is on the top portion of the page! The tricky part is different browsers behave differently and there is no clear idea about when the player starts throttling. So there is no fix solution for the same too.

Well the try to fix thing would be to look for two events  Event.ACTIVATE and Event.DEACTIVATE and start tweaking the code. But then as its known, different browsers have got different implementations, these events are also not consistent !!

I am putting here a little test movie, where there is a SWF embedded in an HTML page, 3 times one after other just to make sure I can hide some SWFs on the page. The SWF is running an ENTER_FRAME based text output in a textfield. Scrolling down and scrolling up on the same page can show the difference in the event calls in the same SWF 🙂

package
{
import flash.display.Sprite;
import flash.events.Event;
import flash.text.TextField;
import flash.text.TextFormat;
public class Throtlling extends Sprite
{
private var enterFrameCounter:int=0;
private var logger:TextField=new TextField();


public function Throtlling()
{
this.init();
}
private function init():void
{
this.logger.width=600;
this.logger.height=200;

this.logger.multiline=true;

this.logger.wordWrap=true;

this.logger.text=’log: ‘;

this.addChild(this.logger);
//
this.addEventListener(Event.ENTER_FRAME,onEachFrame);
//
this.addEventListener(Event.ACTIVATE,onActive);
this.addEventListener(Event.DEACTIVATE,onDeActive);
}

private function onEachFrame(e:Event):void

{
this.enterFrameCounter++;
this.logger.text=(this.enterFrameCounter.toString());

var tf:TextFormat=new TextFormat();

tf.size=100;
this.logger.setTextFormat(tf);
}
private function onActive():void
{
this.logger.text=('Active!');
}
private function onDeActive():void
{
this.logger.text=('Deactivated!!');
}
}
}

Hope that helps someone out there !

Happy Flashing 🙂

Advertisements

Author: saumya

designer / developer / maker / educator @saumya

1 thought on “Flashplayer Throttle : Solving a problem or creating one !”

  1. The key to figuring what’s going wrong on your player, will likely be observation. Try watching carefully how the deck responds when there is no disc inserted. If it seems totally inert, try opening and closing the tray a number of times to see if it ever does spring to life, which might indicate a problem with the tray closed sense switch ( the tray motor might also be trying to still run, even after the tray is fully in ).

Leave a Reply

Fill in your details below or click an icon to log in:

WordPress.com Logo

You are commenting using your WordPress.com account. Log Out / Change )

Twitter picture

You are commenting using your Twitter account. Log Out / Change )

Facebook photo

You are commenting using your Facebook account. Log Out / Change )

Google+ photo

You are commenting using your Google+ account. Log Out / Change )

Connecting to %s