/ Published in: ActionScript 3

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.
Expand |
Embed | Plain Text
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; } } }
Comments

You need to login to post a comment.
Thank you man, I have some question... Can you give me more information how to develop apps for BlackBery with FlashCS5, how to export them and can I run them on BB Curve 8520 for exampe?
I have a few posts on how to develop for CS5. I'm working on a few more that will hopefully be released soon. http://chrisaiv.com/post/4187704195/developing-for-blackberry-playbook-using-flash-cs5