<?xml version="1.0" encoding="utf-8"?>
<mx:WindowedApplication xmlns:mx="http://www.adobe.com/2006/mxml"
showFlexChrome="false"
alwaysInFront="true"
layout="absolute"
width="314"
height="460"
applicationComplete="init();">
<mx:Script>
<![CDATA[
import mx.events.CloseEvent;
private var dockImage:BitmapData;
private function init():void{
bgImage.addEventListener(MouseEvent.MOUSE_DOWN, onStartMove)
var mainMenu:NativeMenu = new NativeMenu();
var minimizeMenu:NativeMenuItem = new NativeMenuItem("Minimize");
var maximizeMenu:NativeMenuItem = new NativeMenuItem("Maximize");
var sepMenu:NativeMenuItem = new NativeMenuItem("",true);
var restoreMenu:NativeMenuItem = new NativeMenuItem("Restore");
var closeMenu:NativeMenuItem = new NativeMenuItem("Close");
// minimizeMenu.addEventListener(Event.Select, handleMenuClick);
// maximizeMenu.addEventListener(Event.Select, handleMenuClick);
// restoreMenu.addEventListener(Event.Select, handleMenuClick);
// closeMenu.addEventListener(Event.Select, handleMenuClick);
mainMenu.addItem(minimizeMenu);
mainMenu.addItem(maximizeMenu);
mainMenu.addItem(sepMenu);
mainMenu.addItem(restoreMenu);
mainMenu.addItem(closeMenu);
this.contextMenu=mainMenu;
var loader:Loader=new Loader();
loader.contentLoaderInfo.addEventListener(Event.COMPLETE,prepareForSystray);//这里就是完成第一步的任务须,这个prepareForSystray就是对托盘的生在和菜单的控制
loader.load(new URLRequest("images/windx_r1_c3.png"));//这里先要加载托盘图标的小图片
this.addEventListener(Event.CLOSING,closingApplication);//设置关闭体的事件
}
public function prepareForSystray(event:Event):void{
dockImage=event.target.content.bitmapData;
if(NativeApplication.supportsSystemTrayIcon){
setSystemTrayProperties();//设置托盘菜单的事件
}
}
private function setSystemTrayProperties():void{
SystemTrayIcon(NativeApplication.nativeApplication .icon).tooltip = "TurboSquid squidword";
SystemTrayIcon(NativeApplication.nativeApplication .icon).addEventListener(MouseEvent.CLICK, undock);
stage.nativeWindow.addEventListener(NativeWindowDisplayStateEvent.DISPLAY_STATE_CHANGING, nwMinimized);
}
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 closingApplication(event:Event):void{
event.preventDefault();
dock();//最小化到托盘
}
//窗口最小化、关闭、拖动函数
public function minimizeWindow():void{
this.stage.nativeWindow.minimize();
}
public function closeWindow():void{
this.stage.nativeWindow.close();
}
public function onStartMove(event:MouseEvent):void{
this.stage.nativeWindow.startMove();
}
]]>
</mx:Script>
<mx:Image x="0" y="0" source="images/airi_login.png" id="bgImage"/>
<mx:TextArea x="35" y="93" width="168" height="25" text="用 名 airia" fontSize="12" cornerRadius="3" color="#000000" themeColor="#01DEFF"/>
<mx:TextArea x="35" y="126" width="168" height="25" text="密 码 ******" color="#000000"/>
<mx:Style source="css.css"/>
<mx:Label x="216" y="374" text="AIRIA Learn 1.0" color="#E0E1E1" fontSize="10" fontFamily="Arial"/>
<mx:Image id="closeImage" click="close()" source="images/windx_r1_c3.png" horizontalCenter="130" verticalCenter="-197" themeColor="#009DFF"/>
<mx:Image id="minimiseImage" click="minimize()" x="260" y="26" source="images/windx_r1_c1.png"/>
<mx:Button x="219" y="95" label="登 陆" width="59.5" height="55" color="#000000" fontSize="14" fontFamily="Arial" fontWeight="normal" fillAlphas="[0.55, 0.55, 0.55, 0.55]"/>
<mx:CheckBox x="35" y="177" label="记住密码" color="#CCCCCC" fontSize="12"/>
<mx:Label x="135" y="179" text="忘记密码?" color="#CCCCCC" fontSize="12"/>
<mx:Image x="35" y="305" source="images/regt2.png" scaleContent="true" />
</mx:WindowedApplication>