<?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 最小化托盘(右下角)
最新推荐文章于 2025-11-26 20:23:01 发布
本文介绍如何使用Adobe Flex创建应用程序,并实现系统托盘图标的功能。文章详细讲解了加载图标资源、设置系统托盘属性、创建托盘菜单以及处理应用最小化到托盘和从托盘恢复显示的操作。
4518

被折叠的 条评论
为什么被折叠?



