Pages

Friday, October 5, 2007

Air App in system Tray with menus

Here is the sample code :

<?xml version="1.0" encoding="utf-8"?>
<mx:WindowedApplication
xmlns:mx="http://www.adobe.com/2006/mxml" layout="absolute"
height="400"
width="500"
creationComplete="init()"
showFlexChrome="false">
<mx:Script>
<![CDATA[
import mx.core.BitmapAsset;
import flash.system.Shell;
import mx.controls.Image;
public var _root:NativeMenu
[Embed(source="icons/AIRApp_16.png")]
[Bindable]
public var imgCls:Class;
function init(){
_root = new NativeMenu()
this.nativeWindow.x = 0
this.nativeWindow.y = 0
trace(Shell.supportsSystemTrayIcon )
var editMenu:NativeMenuItem = _root.addItem(new NativeMenuItem("exit"));
editMenu.addEventListener(Event.SELECT,exitApp)
var imgObj:BitmapAsset = new imgCls() as BitmapAsset;
Shell.shell.icon.bitmaps = [imgObj.bitmapData]
SystemTrayIcon(Shell.shell.icon).menu = _root;

}
public function exitApp(event){
stage.nativeWindow.close()
}
]]>
</mx:Script>
<mx:Canvas height="100%" width="100%" borderStyle="solid" borderColor="#18252E" cornerRadius="20" backgroundColor="#605050">
&ltmx:Button x="54" y="43" label="Close window" click=" stage.nativeWindow.visible=false"/>
</mx:Canvas>
<mx:Image id="myImageRaw" source="{imgCls}" visible="false"/>
</mx:WindowedApplication>

>

No comments: