Revision: 45583
Updated Code
at May 19, 2011 03:46 by chrisaiv
Updated Code
package
{
import flash.desktop.NativeApplication;
import flash.desktop.SystemIdleMode;
import flash.display.Sprite;
import flash.display.StageAlign;
import flash.display.StageScaleMode;
import flash.events.*;
import flash.system.Capabilities;
[SWF(width="1024", height="600", backgroundColor="#f1f1f1", frameRate="24")]
public class Main extends Sprite
{
private static const FRAME_RATE_DEFAULT:Number = 24;
private static const FRAME_RATE_STANDBY:Number = 4
public function Main()
{
stage.align = StageAlign.TOP_LEFT;
stage.scaleMode = StageScaleMode.NO_SCALE;
stage.addEventListener(Event.ACTIVATE, onActivateHandler, false, 0, true );
stage.addEventListener(Event.DEACTIVATE, onDeactivateHandler, false, 0, true );
addEventListener(Event.ADDED_TO_STAGE, init, false, 0, true );
NativeApplication.nativeApplication.addEventListener(Event.EXITING, onExitHandler, false, 0, true );
checkEnvironment()
}
private function checkEnvironment():void
{
if (Capabilities.manufacturer.indexOf('VMware') == -1) {
//It is a BlackBerry PlayBook Tablet.
} else {
//It is a BlackBerry PlayBook Simulator.
}
}
private function init( e:Event ):void
{
//Self Destruct Handler
e.currentTarget.removeEventListener(e.type, arguments.callee );
}
private function onExitHandler( e:Event ):void
{
NativeApplication.nativeApplication.exit(0);
}
private function onActivateHandler( e:Event ):void
{
//trace( "Main::onActivateHandler:" );
stage.frameRate = FRAME_RATE_DEFAULT;
NativeApplication.nativeApplication.systemIdleMode = SystemIdleMode.KEEP_AWAKE;
}
private function onDeactivateHandler( e:Event ):void
{
stage.frameRate = FRAME_RATE_STANDBY;
NativeApplication.nativeApplication.systemIdleMode = SystemIdleMode.NORMAL;
}
}
}
Revision: 45582
Updated Code
at May 4, 2011 16:16 by chrisaiv
Updated Code
package
{
import flash.desktop.NativeApplication;
import flash.desktop.SystemIdleMode;
import flash.display.Sprite;
import flash.display.StageAlign;
import flash.display.StageScaleMode;
import flash.events.*;
[SWF(width="1024", height="600", backgroundColor="#f1f1f1", frameRate="24")]
public class Main extends Sprite
{
private static const FRAME_RATE_DEFAULT:Number = 24;
private static const FRAME_RATE_STANDBY:Number = 4
public function Main()
{
stage.align = StageAlign.TOP_LEFT;
stage.scaleMode = StageScaleMode.NO_SCALE;
stage.addEventListener(Event.ACTIVATE, onActivateHandler, false, 0, true );
stage.addEventListener(Event.DEACTIVATE, onDeactivateHandler, false, 0, true );
addEventListener(Event.ADDED_TO_STAGE, init, false, 0, true );
NativeApplication.nativeApplication.addEventListener(Event.EXITING, onExitHandler, false, 0, true );
NativeApplication.nativeApplication.systemIdleMode = SystemIdleMode.KEEP_AWAKE;
}
private function init( e:Event ):void
{
//Self Destruct Handler
e.currentTarget.removeEventListener(e.type, arguments.callee );
}
private function onExitHandler( e:Event ):void
{
NativeApplication.nativeApplication.exit(0);
}
private function onActivateHandler( e:Event ):void
{
//trace( "Main::onActivateHandler:" );
stage.frameRate = FRAME_RATE_DEFAULT;
}
private function onDeactivateHandler( e:Event ):void
{
stage.frameRate = FRAME_RATE_STANDBY;
}
}
}
Revision: 45581
Initial Code
Initial URL
Initial Description
Initial Title
Initial Tags
Initial Language
at May 4, 2011 16:15 by chrisaiv
Initial Code
package
{
import flash.desktop.NativeApplication;
import flash.desktop.SystemIdleMode;
import flash.display.Sprite;
import flash.display.StageAlign;
import flash.display.StageScaleMode;
import flash.events.*;
[SWF(width="1024", height="600", backgroundColor="#f1f1f1", frameRate="24")]
public class Main extends Sprite
{
private static const FRAME_RATE_DEFAULT:Number = 24;
private static const FRAME_RATE_STANDBY:Number = 4
public function Main()
{
stage.align = StageAlign.TOP_LEFT;
stage.scaleMode = StageScaleMode.NO_SCALE;
stage.addEventListener(Event.ACTIVATE, onActivateHandler, false, 0, true );
stage.addEventListener(Event.DEACTIVATE, onDeactivateHandler, false, 0, true );
NativeApplication.nativeApplication.addEventListener(Event.EXITING, onExitHandler, false, 0, true );
NativeApplication.nativeApplication.systemIdleMode = SystemIdleMode.KEEP_AWAKE;
}
private function onExitHandler( e:Event ):void
{
NativeApplication.nativeApplication.exit(0);
}
private function onActivateHandler( e:Event ):void
{
//trace( "Main::onActivateHandler:" );
stage.frameRate = FRAME_RATE_DEFAULT;
}
private function onDeactivateHandler( e:Event ):void
{
stage.frameRate = FRAME_RATE_STANDBY;
}
}
}
Initial URL
Initial Description
It seems that every time I work on a Blackberry app, by default I use some boilerplate code like this. The idea is simply to handle the background events whenever a user flips to another application.
Initial Title
AS3: Blackberry Playbook Boilerplate
Initial Tags
Initial Language
ActionScript 3