<?xml version="1.0" encoding="utf-8"?> <s:WindowedApplication xmlns:fx="http://ns.adobe.com/mxml/2009" xmlns:s="library://ns.adobe.com/flex/spark" xmlns:mx="library://ns.adobe.com/flex/mx" > <fx:Script> <![CDATA[ import mx.controls.Alert; import mx.events.CloseEvent; private var dockImage:BitmapData; public function initApplication():void { var loader:Loader = new Loader(); loader.contentLoaderInfo.addEventListener(Event.COMPLETE, prepareForSystray); loader.load(new URLRequest("assets/ok.png")); this.addEventListener(Event.CLOSING, closingApplication); } private function closingApplication(evt:Event):void { evt.preventDefault(); Alert.yesLabel = "Close"; Alert.noLabel = "Minimize"; Alert.show("Close or minimize?", "Close?", 3, this, alertCloseHandler); } private function alertCloseHandler(event:CloseEvent):void { if (event.detail==Alert.YES) { closeApp(event); } else { dock(); } } public function prepareForSystray(event:Event):void { dockImage = event.target.content.bitmapData; if (NativeApplication.supportsSystemTrayIcon){ setSystemTrayProperties(); SystemTrayIcon(NativeApplication.nativeApplication .icon).menu = createSystrayRootMenu(); } } private function createSystrayRootMenu():NativeMenu{ var menu:NativeMenu = new NativeMenu(); var openNativeMenuItem:NativeMenuItem = new NativeMenuItem("Open"); var exitNativeMenuItem:NativeMenuItem = new NativeMenuItem("Exit"); openNativeMenuItem.addEventListener(Event.SELECT, undock); exitNativeMenuItem.addEventListener(Event.SELECT, closeApp); menu.addItem(openNativeMenuItem); menu.addItem(new NativeMenuItem("",true)); menu.addItem(exitNativeMenuItem); return menu; } private function setSystemTrayProperties():void{ SystemTrayIcon(NativeApplication.nativeApplication .icon).tooltip = "Systray test application"; SystemTrayIcon(NativeApplication.nativeApplication .icon).addEventListener(MouseEvent.CLICK, undock); stage.nativeWindow.addEventListener(NativeWindowDisplayStateEvent.DISPLAY_STATE_CHANGING, nwMinimized); //Catch the minimize event } private function nwMinimized(displayStateEvent:NativeWindowDisplayStateEvent):void { if(displayStateEvent.afterDisplayState == NativeWindowDisplayState.MINIMIZED) { displayStateEvent.preventDefault(); dock(); } } public function dock():void { stage.nativeWindow.visible = false; NativeApplication.nativeApplication .icon.bitmaps = [dockImage]; } public function undock(evt:Event):void { stage.nativeWindow.visible = true; stage.nativeWindow.orderToFront(); NativeApplication.nativeApplication .icon.bitmaps = []; } private function closeApp(evt:Event):void { stage.nativeWindow.close(); NativeApplication.nativeApplication .icon.bitmaps = []; //clean this icon } ]]> </fx:Script> <s:Button click="closingApplication(event);" creationComplete="initApplication()"/> </s:WindowedApplication>
FB4 AIR 最小化托盘(右下角)
猜你喜欢
转载自namas.iteye.com/blog/1167864
今日推荐
周排行