Advertisement
peter9477

PlayBook auto-orientation event tests

Feb 24th, 2012
88
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
  1. package {
  2.     import flash.display.Sprite;
  3.     import flash.display.StageAlign;
  4.     import flash.display.StageScaleMode;
  5.     import flash.events.*;
  6.  
  7.     import qnx.ui.text.Label;
  8.     import qnx.display.IowWindow;
  9.  
  10.     [SWF(backgroundColor="#dddddd")]
  11.     public class AutoOrientTest extends Sprite {
  12.         private var label:Label;
  13.  
  14.         public function AutoOrientTest() {
  15.             stage.align = StageAlign.TOP_LEFT;
  16.             stage.scaleMode = StageScaleMode.NO_SCALE;
  17.  
  18.             label = new Label();
  19.             label.height = 100;
  20.             label.width = 600;
  21.             label.text = "Auto-orient test";
  22.             addChild(label);
  23.  
  24.             makeline();
  25.  
  26.             stage.addEventListener(StageOrientationEvent.ORIENTATION_CHANGING, handleOrientationChanging);
  27.             stage.addEventListener(StageOrientationEvent.ORIENTATION_CHANGE, handleOrientation);
  28.             addEventListener(Event.ACTIVATE, onActivate);
  29.         }
  30.  
  31.         private function onActivate(e:Event):void {
  32.             trace(e.type, stage.orientation);
  33.             label.text = e.type + ": " + stage.orientation;
  34.             makeline();
  35.         }
  36.  
  37.         private function handleOrientationChanging(e:StageOrientationEvent):void {
  38.             trace(e);
  39.             if (e.afterOrientation == 'rotatedRight')
  40.                 e.preventDefault();
  41.         }
  42.  
  43.         private function handleOrientation(e:StageOrientationEvent):void {
  44.             trace(e.type, e.beforeOrientation, e.afterOrientation, stage.orientation);
  45.             label.text = e.type + ": " + stage.orientation;
  46.             makeline();
  47.         }
  48.  
  49.         private function makeline():void {
  50.             graphics.clear();
  51.             graphics.lineStyle(5, 0x88ff00);
  52.             graphics.moveTo(5, 5);
  53.             graphics.lineTo(stage.stageWidth - 5, stage.stageHeight - 5);
  54.         }
  55.     }
  56. }
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement