Monday, June 13, 2011

Create an Adobe ActionScript application


Use the following code sample to create an Adobe® ActionScript® application named AIRHelloWorld.

Before you begin: Create an image in PNG format with a maximum resolution of 86 x 86 pixels named blackberry-tablet-icon.png to use as the icon for your application. If you create the image file in the same folder as your compiled application, the application packaging tool that is included in the BlackBerry® Tablet OS SDK adds this image to your application automatically. For more information about adding an icon for your application, see "Create an XML configuration file for your icon".
  1. In a text editor, paste the following code sample.
    package 
    {
     import flash.display.Sprite;
     import flash.events.MouseEvent;
     import flash.text.TextField;
     import flash.text.TextFormat;
     import qnx.ui.buttons.Button;
     import qnx.ui.buttons.LabelButton;
    
     [SWF(width="1024", height="600", backgroundColor="#cccccc", frameRate="30")]
     public class AIRHelloWorld extends Sprite
     {
      public function AIRHelloWorld()
      {
       var helloButton:LabelButton = new LabelButton();
       helloButton.label = "Hello World!";
       helloButton.x = (stage.stageWidth - helloButton.width)/2;
       helloButton.y = (stage.stageHeight - helloButton.height)/2;
       
       var myFormat:TextFormat = new TextFormat();
       myFormat.color = 0xAA0000;   
       myFormat.size = 24;  
       myFormat.italic = true;  
       myFormat.align = "center";
    
       var text:TextField = new TextField();
       text.text = "Close";
       text.setTextFormat(myFormat);
       
       var closeButton:Button = new Button();
       closeButton.addChild(text);  
       closeButton.addEventListener(MouseEvent.CLICK, closeWindow);
       closeButton.x = (stage.stageWidth - closeButton.width)/2;
       closeButton.y = helloButton.y - helloButton.height;
       
       addChild(helloButton);
       addChild(closeButton);
       
       stage.nativeWindow.visible = true;
      }
      
      private function closeWindow(event:MouseEvent):void{
       stage.nativeWindow.close();
      }
     }
    }
    
  2. Save the file as AIRHelloWorld.as.

No comments:

Post a Comment