Category Archives: iPhone

Store data in AIR applications for iOS devices

Saving state on iOS devices

We envisioned the scenario of applications that lose data when they are interrupted. Of course, the built-in iOS apps don’t do that—when you go back to your text messages after that interrupting phone call, you pick up right where you left off. This is done by the simple expedient of saving state when the application is ordered to quit by the OS. In the Objective-C world, you will have to implement this yourself (see the appropriate section of the iOS Application Programming Guide), and it is no different when you are developing with Flash.

Saving on exit

How do you know when to save in Flash? Since AIR applications for iOS share the same API as AIR apps for Adobe AIR, you can listen for the NativeApplication.EXITING event to know when to save your state:

    import flash.desktop.NativeApplication;
    import flash.display.Sprite;

    public class Save1 extends Sprite
        public function Save1()
            // Listen for exiting event.   
            NativeApplication.nativeApplication.addEventListener(Event.EXITING, onExit);

            // Load data.           ;
        private function onExit(e:Event):void
            trace("Save here.");

        private function load():void
            trace("Load here.");

Read more :
Leave a comment

Posted by on November 11, 2011 in Action Script3, Adobe Air, iPhone


Flash Player 11 and AIR 3 Now Available

Flash Player 11 and AIR 3 are now available for download.

For additional information including detailed information on new features, please see this release notes.


How to use Flash Player 11 & AIR 3 with Flash Professional CS5.5

Issue : VerifyError: Error #1014: La classe flash.display3D::Context3D could not be found.

Stage3D will work with web browser. For remove this above issue, set  wmode=”DIRECT” in HTML 


Download Adobe AIR 3 SDK from here 

Download the PlayerGlobal.swc to target the 11.0 APIs(for FlashPlayer 11) from here

Targeting Adobe Flash Player 11 Release Candidate for Desktops.

1.- Download the Flash Player 11 Release Candidate.
First things first go to the Adobe Labs site and download the Adobe Flash Player 11 Release Candidate for Desktops. Download the proper player for Your system ( Is important that You download and install the runtime on Your browser otherwise you won’t be able to test your SWFs as there is no Standalone RC1 version). You need to download the Flash Player 11 Release Candidate Global SWC “playerglobal.swc” as well.

2.- Once You installed Flash Player in the browser and renamed the swc file from flashplayer11_rc1_playerglobal_090611 to “playerglobal.swc” go to “/Applications/Adobe Flash CS5.5/Common/Configuration/ActionScript 3.0″ and create a new folder i named mine FP11_RC1 and copy your playerglobal.swc file inside the folder you just created.

3.- Now You need a new player profile so You can choose the Flash Player 11 RC1 from the available player versions when working with Flash, go to “ /Applications/Adobe Flash CS5.5/Common/Configuration/Players/”  duplicate the FlashPlayer10_2 2.xml and give it a new name to the file You just copy I named mine FlashPlayer11_RC1.xml.

4.- Open that file in a text editor and change the id and version in the player tag for id give it the name You wish to be displayed in the Player panel inside of Flash I named mine “FlashPlayer11_RC1″ and change the version to “13″.

6.- Save the file open Flash CS5.5 and You’re good to go.

Targeting Adobe AIR 3 Release Candidate.

1.- Download the AIR 3.0 Release Candidate.
First thing You need is the Adobe AIR 3 SDK Release Candidate.

2.- Unzip Your AIR SDK if You’re on Mac the file will be named ” air3_rc1_sdk_mac_090611.tbz2″

3.- Close Flash Professional CS5.5 and browse o the AIR 2.6 folder, on Mac it will be in the following location
“/Applications/Adobe Flash CS5.5”

4.- Change the AIR2.6 folder name to something like AIR2.6_old.

5.- Rename the folder You previously unzipped to AIR2.6 and place it on the Flash Professional CS5.5 folder “/Applications/Adobe Flash CS5.5”.

6.- Browse to the AIR2.6/frameworks/libs/air/ folder and copy the airglobal.swc.

7.- Paste the SWC file in the folder “/Applications/Adobe Flash CS5.5/Common/Configuration/ActionScript 3.0/AIR2.6” it wil replace your copy of  the airglobal.swf file.

8.- Browse to the “/Applications/Adobe Flash CS5.5/Common/Configuration/Players” folder and open the following files with a text editor:  AdobeAIR2_6.xml, AiriPhone.xml, or Android.xml.

9.- Change the version attribute in the player tag from 11 to 13 and save the files:

On the Android xml file: <player id="android_0" version="13" asversion="3" minasversion="3"></player>

On the AdobeAIR2_6 xml file: <player id="AdobeAIR2_6" version="13" asversion="3" minasversion="3"></player>

10.- Browse to the “/Applications/Adobe Flash CS5.5/AIR2.6/samples/” and open the descriptor-sample.xml file.

11.- Change the “; namespace URL to “;.

<application xmlns="" minimumpatchlevel="0"></application>

12.- Save the file and open Flash.


Testing time: Click Here for Read More


audio and video streaming with StageWebView and html5

The StageWebView object  is a powerful way to integrate the elements that AIR is lacking today. Do you need a list with perfect scrolling ? AAC audio streaming ? H.264 streaming ? Well you can use a StageWebView to load “HTML5″ code inside the AIR app and integrate this kind of content. Let’s do a simple example:

var webView = new StageWebView();
webView.stage = this.stage;
webView.viewPort = new Rectangle( 0, 0, stage.stageWidth, stage.stageHeight);
var path:String = new File(new File("app:/html/service.htm").nativePath).url;

This code will open a fullscreen instance of the native browser (without UI) and load a locally stored .html file (notice that it is necessary in iOS to use some hack like that at line 4 to obtain a valid url to access local html). Now you can easily understand that the best is to mix AIR UI and this windowed browser to exploit HTML5 capabilities especially for media streaming. A simple <video> tag inside the html code can do the job and offer perfect H.264 progressive and streaming playback to your AIR apps both in window and at fullscreen.



ActionScript APIs specific to mobile AIR applications

The following APIs are available only in AIR applications on mobile devices. They are not currently functional in Flash Player or desktop versions of AIR.

Screen orientation API

The screen orientation API lets you work with the orientation of the stage and the iPhone:

  • Stage.autoOrients— Whether the application is set to have the stage automatically reorient when the device is rotated. This property is set to true when the Auto Orientation option is selected in the Flash Professional CS5 iPhone Settings dialog box. (You can also set the autoOrients element to true in the application descriptor file.) See iPhone application settings. You can cancel the automatic reorientation by adding anorientationChanging event listener for the Stage object. Calling the preventDefault() method of this event object cancels the automatic reorientation.

    When using auto-orientation, for best results set the align property of the Stage to the following:

    stage.align = StageAlign.TOP_LEFT; 
    stage.scaleMode = StageScaleMode.NO_SCALE;
  • Stage.deviceOrientation—The physical orientation of the device. The StageOrientation class defines values for this property.
  • Stage.orientation—The current orientation of the stage. The StageOrientation class defines values for this property.
  • Stage.supportsOrientationChange—Set to true on the iPhone, and false in an AIR application.
  • Stage.setOrientation()—Sets the orientation of the stage. This method has one parameter, which is a string defining the new stage orientation. The constants in the StageOrientation class define possible values for the parameter.
  • StageOrientation—Defines stage orientation values. For example, StageOrientation.ROTATED_RIGHT indicates a stage that is rotated right relative to the default orientation of the device.
  • StageOrientationEvent—Defines events that the Stage dispatches when the orientation of the screen changes. This event occurs when the user rotates the iPhone. There are two types of events. The Stage dispatches theorientationChanging event as the device is being rotated. To prevent the stage from reorienting, call the preventDefault() method of the orientationChanging event object. The Stage dispatches theorientationChange event once the stage reorientation is complete.

Currently, the screen orientation API is only useful in AIR applications on mobile devices. If a mobile AIR application and a desktop AIR application share source code, use the Stage.supportsOrientationChange property to check if the API is supported.

The following example shows how to respond to the user rotating the device:


function onOrientationChange(event:StageOrientationEvent):void 
    switch (event.afterOrientation) { 
        case StageOrientation.DEFAULT: 
            // re-orient display objects based on 
            // the default (right-side up) orientation. 
        case StageOrientation.ROTATED_RIGHT: 
            // Re-orient display objects based on 
            // right-hand orientation. 
        case StageOrientation.ROTATED_LEFT: 
            // Re-orient display objects based on 
            // left-hand orientation. 
        case StageOrientation.UPSIDE_DOWN: 
            // Re-orient display objects based on 
            // upside-down orientation. 

In this example, in the case of different stage orientations, there are comments instead of functional code.

You can change the orientation of the stage by calling the setOrientation() method of the Stage object. Setting the orientation is an asynchronous operation. You can check when the orientation is complete by listening for theorientationChange event. The following code shows how to set the stage to the right-hand orientation:


function onOrientationChange(event:StageOrientationEvent):void 
    // Code to handle the new Stage orientation 

As the Stage rotates it resizes, and the Stage object dispatches a resize event. You can resize and reposition display objects on the Stage in response to the resize event.

NativeApplication.systemIdleMode and SystemIdleMode

The NativeApplication.systemIdleMode property lets you prevent the iPhone from going into idle mode. By default, an iPhone goes into idle mode if there is no touch screen interaction for some period. Idle mode can cause the screen to dim. It can also cause the iPhone to go into lock mode. This property can be set to one of two values:

  • SystemIdleMode.NORMAL—The iPhone follows the normal idle mode behavior.
  • SystemIdleMode.KEEP_AWAKE—The application attempts to prevent the iPhone from going into idle mode.

This functionality is only supported on mobile devices. It is not supported in AIR applications running on desktop operating systems. In an application running on the desktop, setting the NativeApplication.systemIdleModeproperty has no effect.

The following code shows how to disable the iPhone idle mode:

NativeApplication.nativeApplication.systemIdleMode = SystemIdleMode.KEEP_AWAKE;


The CameraRoll class lets you add an image to the iPhone camera roll. The addBitmapData() method adds an image to the iPhone camera roll. The method has one parameter, bitmapData. This parameter is the BitmapData object containing the image to add to the camera roll.

CameraRoll functionality is only supported on mobile devices. It is not supported in AIR applications running on desktop operating systems. To check at runtime whether your application supports the CamerRoll functionality, check the static CameraRoll.supportsAddBitmapData property.

After you call the addBitmapData() method, the CameraRoll object dispatches one of two events:

  • complete—The operation completed successfully.
  • error—There was an error. For example, perhaps there is not enough free space on the iPhone to store the image.

The following code adds an image of the stage (a screen capture) to the camera roll:

if (CameraRoll.supportsAddBitmapData) 
    var cameraRoll:CameraRoll = new CameraRoll(); 
    cameraRoll.addEventListener(ErrorEvent.ERROR, onCrError); 
    cameraRoll.addEventListener(Event.COMPLETE, onCrComplete); 
    var bitmapData:BitmapData = new BitmapData(stage.stageWidth, stage.stageHeight); 
    trace("not supported."); 

function onCrError(event:ErrorEvent):void 
    // Notify user. 

function onCrComplete(event:Event):void 
    // Notify user. 


The cacheAsBitmapMatrix property is a Matrix object that defines how a display object is rendered when cacheAsBitmap is set to true. The application uses this matrix as a transformation matrix when rendering the bitmap version of the display object.

With cacheAsBitmapMatrix set, the application retains a cached bitmap image rendered using that matrix, instead of the display matrix. (The display matrix is the value of the transform.concatenatedMatrix of the display object.) If this matrix does not match the display matrix, the bitmap is scaled and rotated as necessary.

A display object with cacheAsBitmapMatrix set is only rerendered when the value of cacheAsBitmapMatrix changes. The bitmap is scaled or rotated as appropriate to conform to the display matrix.

Both CPU- and GPU-based rendering benefit from the use of the cacheAsBitmapMatrix property, although GPU rendering typically benefits more.

Note: To use the hardware acceleration, set the Rendering to GPU in the General tab of the iPhone Settings dialog box in Flash Professional CS5. (Or set the renderMode property to gpu in the application descriptor file.)

For example, the following code uses an untransformed bitmap representation of the display object:

matrix:Matrix = new Matrix(); // creates an identity matrix 
mySprite.cacheAsBitmapMatrix = matrix; 
mySprite.cacheAsBitmap = true;

The following code uses a bitmap representation that matches the current rendering:

mySprite.cacheAsBitmapMatrix = mySprite.transform.concatenatedMatrix; 
mySprite.cacheAsBitmap = true;

Usually, the identity matrix (new Matrix()) or transform.concatenatedMatrix suffices. However, you can use another matrix, such as a scaled-down matrix, to upload a different bitmap to the GPU. For example, the following example applies a cacheAsBitmapMatrix matrix that is scaled by 0.5 on the x- and y-axes. The bitmap object that the GPU uses is smaller, however the GPU adjusts its size to match the transform.matrix property of the display object.:

matrix:Matrix = new Matrix(); // creates an identity matrix 
matrix.scale(0.5, 0.5); // scales the matrix 
mySprite.cacheAsBitmapMatrix = matrix; 
mySprite.cacheAsBitmap = true;

Generally, choose a matrix that transforms the display object to the size that it will appear in the application. For example, if your application displays the bitmap version of the sprite scaled down by a half, use a matrix that scales down by a half. If your application will display the sprite larger than its current dimensions, use a matrix that scales up by that factor.

There is a practical limit to the size of display objects for which the cacheAsBitmapMatrix property is set. The limit is 1020 by 1020 pixels. There is a practical limit for the total number of pixels for all display objects for which the cacheAsBitmapMatrix property is set. That limit is about four million pixels.

There are many considerations when using cacheAsBitmapMatrix and hardware acceleration. It is important to know which display objects should have that property set, and which ones should not. For important information on using this property, see Hardware acceleration.

You can use the GPU rendering diagnostics feature to diagnose GPU usage in debug builds of your application. For more information, see Debugging an iPhone application.

Networking notes

Using the following URL schemes with the nativigateToURL() function causes a document to open in an external application:

URL scheme Result of call to nativeToURL() Example
mailto: Opens a new message in the mail application.
str = ""; 
var urlReq:URLReq = new URLRequest(str); 
sms: Opens a message in the text message application.
str = "sms:1-415-555-1212"; 
var urlReq:URLReq = new URLRequest(str); 
tel: Dials a phone number on the phone (with user approval).
str = "tel:1-415-555-1212"; 
var urlReq:URLReq = new URLRequest(str); 

An iPhone application may rely on installed self-signed root certificates for server authentication during a secure transaction, such as an https request. A server should send not just the leaf certificate but also all intermediate certificates chaining to the root certificate.


Leave a comment

Posted by on September 11, 2011 in Adobe Air, Android, flash, iPhone, Mobile Technology


StageWebViewBridge is an extended version of

Communicate with StageWebView

It is not so easy to communicate with the page loaded inside the StageWebView. The object does not provide specifics API. Fortunately exist a class (StageWebViewBridge) developed to overcome the limitations of the standard StageWebView object. With StageWebViewBridgeit is possible to communicate bidirectionally with the hosted html page and so create something similar to PhoneGap with Flash AIR.

Waiting for the future AIR 2.7 (which could have yet problems in the video area if it does not implement StageVideo in iOS) this is the best solution I found to overcome the limitations of AIR for iOS.

It lets you:

  • Communicate Actionscript with Javascript.
  • Communicate Javascript with Actionscript.
  • Load local files and resources in a easy way.
  • Extend loadString method with AS3 – JS communication.

By example you can call javascript from as3

// call javascript with callack function'someFunctionToCall', callBackFunction, ...arguments );

// reference local resources in a easy way
<img src="appfile:/image.png">

Leave a comment

Posted by on September 11, 2011 in Adobe Air, Android, flash, iPhone


Uploading images from CameraRoll and CameraUI

Getting the media promise

The first step is to request the image from either the CameraRoll or the CameraUI object. In both cases, you create the appropriate object, set up some event listeners, and then call the function that asks for the image. The runtime then returns the image in an event containing the media promise after the user has either chosen a picture from the device media library or taken a new picture with the camera.


The following code example sets up the event listeners necessary to handle the events that can be dispatched by a CameraRoll object and then calls the browseForImage() method. When the user selects an image, the runtime calls an event handler function named, imageSelected.
//declare cameraRoll where it won’t go out of scope
var cameraRoll:CameraRoll = new CameraRoll();

if( CameraRoll.supportsBrowseForImage )
cameraRoll.addEventListener( MediaEvent.SELECT, imageSelected );
cameraRoll.addEventListener( Event.CANCEL, browseCanceled );
cameraRoll.addEventListener( ErrorEvent.ERROR, mediaError );
trace( “Image browsing is not supported on this device.”);


The code for requesting an image from the CameraUI object is very similar:
private var cameraUI:CameraUI = new CameraUI();
if( CameraUI.isSupported )
trace( “Initializing…” );
cameraUI.addEventListener( MediaEvent.COMPLETE, imageSelected );
cameraUI.addEventListener( Event.CANCEL, browseCanceled );
cameraUI.addEventListener( ErrorEvent.ERROR, mediaError );
cameraUI.launch( MediaType.IMAGE );
trace( “CameraUI is not supported.”);

Click here for Download soruce.