The following article will introduce the code snippets that are new in the mobile applications. These are basically the ones that handle the physical buttons and the rotation features of the mobile devices.

When creating a mobile application, you need to use the File->New->Flex Mobile Project option and set the project name, the target platform (Android, iPhone or BlackBerry)
The following program code (Code 1) shows how you can handle the physical buttons of a mobile device. These instructions should be placed in the creationComplete handler of the application.

1.	if(Capabilities.cpuArchitecture=="ARM")  
2.	{  
3.	        NativeApplication.nativeApplication.addEventListener(Event.ACTIVATE, handleActivate, false, 0, true);  
4.	        NativeApplication.nativeApplication.addEventListener(Event.DEACTIVATE, handleDeactivate, false, 0, true);  
5.	        NativeApplication.nativeApplication.addEventListener(KeyboardEvent.KEY_DOWN, handleKeys, false, 0, true);  
6.	}
Code 1 - Handling the physical buttons of the device

In Code 2 the event handler functions for handling buttons are listed. You can see that there is no difficulty to handle these buttons within the Adobe Flash code.

1.	private function handleActivate(event:Event):void  
2.	{  
3.	        NativeApplication.nativeApplication.systemIdleMode = SystemIdleMode.KEEP_AWAKE;  
4.	}  
6.	private function handleDeactivate(event:Event):void  
7.	{  
8.	        NativeApplication.nativeApplication.exit();  
9.	}  
11.	private function handleKeys(event:KeyboardEvent):void  
12.	{  
13.	        if(event.keyCode == Keyboard.BACK)  
14.	                NativeApplication.nativeApplication.exit();  
15.	}
Code 2 - The event handlers for the device buttons

You can distinguish between the horizontal and vertical layout of the mobile devices, too. If the layout needs to be rearranged when the device is rotated, you can do that by defining states in your application and change these states when the device is rotated (Code 3).

1.	private function StageOrientationChange(soce:StageOrientationEvent):void  
2.	{  
3.	        if(soce.afterOrientation=="default" || soce.afterOrientation=="upsideDown")  
4.	        {  
5.	                this.currentState="Vertical";  
6.	        } else  
7.	        {  
8.	                this.currentState="Horizontal";  
9.	        }  
10.	}
Code 3 - Rotation notification for the mobile device

You need to subscribe for the orientation change event in the creationComplete event handler, too. Code 4 shows how you can do this.

1.	this.currentState="Vertical";  
2.	systemManager.stage.addEventListener(StageOrientationEvent.ORIENTATION_CHANGE,StageOrientationChange);
Code 4 - Subscribing for the rotation event

Basically these were the functions and instructions that are needed to add in the mobile code but above these the program is the same as the web solutions.

When the programming state is over, you can easily save the code in the proper file format by using the File->Export menu option where you can specify target platform and for example get an .apk file for the Android devices.