<?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"
backgroundAlpha="0.5" backgroundColor="#727070"
width="245" height="505" creationComplete="initSystary()"
showStatusBar="false" usePreloader="false"
mouseDown="this.nativeWindow.startMove()">
<fx:Declarations>
<!-- 将非可视元素(例如服务、值对象)放在此处 -->
</fx:Declarations>
<fx:Style>
@namespace s "library://ns.adobe.com/flex/spark";
@namespace mx "library://ns.adobe.com/flex/mx";
mx|Alert {
titleStyleName: "alertTitle";
messageStyleName: "alertMessage";
button-style-name:"alertButtons";
borderColor: #831201;
borderAlpha: 0.5;
backgroundColor: #cccccc;
backgroundAlpha: 0.5;
cornerRadius:5;
headerHeight:0;
}
.alertTitle {
letterSpacing: 0;
fontSize: 14;
color: #000000;
fontFamily: "_sans";
}
.alertMessage {
letterSpacing: 0;
fontSize: 12;
fontWeight: bold;
color: #000000;
fontFamily: "_sans";
}
.alertButtons{
cornerRadius:5;
fillAlphas:0.0,0.0,0.0,0.0;
fillColors:#aaaaaa, #aaaaaa, #aaaaaa, #aaaaaa;
color:#000000;
textRollOverColor:#FFFFFF;
borderColor:#862e1d;
themeColor:#862e1d;
fontFamily:Arial;
fontSize:12; fontWeight:bold;
}
mx|ToolTip{
backgroundAlpha: 0.5;
cornerRadius: 6;
backgroundColor: #999999;
color: #0b333c;
fontSize: 12;
fontWeight: bold;
}
</fx:Style>
<fx:Script>
<![CDATA[
import flash.events.Event;
import mx.controls.Alert;
import mx.events.CloseEvent;
private var dockImage:BitmapData;
//初始化
public function initSystary():void{
var loader:Loader=new Loader();
loader.contentLoaderInfo.addEventListener(Event.COMPLETE,prepareForSystray);//这里就是完成第一步的任务须,这个prepareForSystray就是对托盘的生在和菜单的控制
loader.load(new URLRequest("assets/icon_16.png"));//这里先要加载托盘图标的小图片
}
//生成托盘
public function prepareForSystray(event:Event):void{
dockImage=event.target.content.bitmapData;
if(NativeApplication.supportsSystemTrayIcon){
setSystemTrayProperties();//设置托盘菜单的事件
SystemTrayIcon(NativeApplication.nativeApplication.icon).menu=createSystrayRootMenu();//生成托盘菜单
}
}
//关闭窗体的事件
public function closingApplication(event:Event):void{
event.preventDefault();//阻止默认的事件
Alert.yesLabel="关闭";
Alert.noLabel="最小化";
Alert.show("关闭 或者 最小化?", "", 3, this, alertCloseHandler);//弹出自定义的选择框, 关于Alert的详细用法,参考官方文档或我前面的相关文章.
}
//根据用户的选择来判断做什么,这里选择是就是关闭,选择否(Mini)就是最小化到托盘.
private function alertCloseHandler(event:CloseEvent):void{
if(event.detail==Alert.YES){
closeApp(event);
}else{
dock();//最小化到托盘
}
}
public function createSystrayRootMenu():NativeMenu{
var menu:NativeMenu = new NativeMenu();
var openNativeMenuItem:NativeMenuItem = new NativeMenuItem("打开");//生成OPEN菜单项
var exitNativeMenuItem:NativeMenuItem = new NativeMenuItem("退出");//同理
openNativeMenuItem.addEventListener(Event.SELECT, undock);
exitNativeMenuItem.addEventListener(Event.SELECT, closeApp);//添加EXIT菜单项事件
menu.addItem(openNativeMenuItem);
menu.addItem(new NativeMenuItem("",true));//separator
menu.addItem(exitNativeMenuItem);//将菜单项加入菜单
return menu;
}
//设置托盘图标的事件
private function setSystemTrayProperties():void{
SystemTrayIcon(NativeApplication.nativeApplication .icon).tooltip = "迷你虾米";
SystemTrayIcon(NativeApplication.nativeApplication .icon).addEventListener(MouseEvent.CLICK, undock);
this.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 {
this.stage.nativeWindow.visible = false; //设置本地程序窗体不可见
NativeApplication.nativeApplication.icon.bitmaps = [dockImage];//设置托盘的图标
}
//激活程序窗体
public function undock(evt:Event):void {
this.stage.nativeWindow.visible = true;//设置本地程序窗体可见
this.stage.nativeWindow.orderToFront();//设置本地程序窗体到最前端
NativeApplication.nativeApplication .icon.bitmaps = [];//将托盘图标清空
}
//关闭程序窗体
private function closeApp(evt:Event):void {
this.stage.nativeWindow.close();
}
]]>
</fx:Script>
<mx:HTML left="5" right="5" top="20" bottom="5" borderVisible="false" dropShadowVisible="true">
<mx:htmlText><![CDATA[<embed src="http://www.xiami.com/widget/933399_3647936,92815,1769398935,1770041365,358220,2859781,1017664,3598821,2117684,1770465833,1769836929,1768925137,1769893096,1769880107,1769880770,1769872306,1769529110,1769865841,1769731118,1769863941,1769571068,1769833050,1769868710,1769832126,3430594,1769701067,1769802256,1769832129,1768983626,1769470092,1769642275,1769399774,3492156,1769845026,1769908306,1769227477,1769372162,1769292118,7336,3480144,1769899857,384840,1769000347,1769183201,3455559,3567313,3484274,1769472424,72256,1769472432,_235_480_5695c1_457cb4/multiPlayer.swf" type="application/x-shockwave-flash" width="235" height="480" wmode="opaque"></embed>]]></mx:htmlText>
</mx:HTML>
<mx:LinkButton right="0" top="0" width="25" height="20" label="X" cornerRadius="4"
fontWeight="bold" toolTip="关闭" click="closingApplication(event)"/>
<mx:LinkButton right="25" top="0" width="25" height="20" label="-" fontSize="16"
fontWeight="bold" toolTip="最小化" click="dock()"/>
</s:WindowedApplication>
分享到:
相关推荐
关闭窗口弹出是否关闭的提示 最小化窗口后显示在系统托盘中 tooltip为测试生成托盘图标 托盘图标右键可以打开和关闭
Flex3Air最小化到系统托盘 跨来下载吧,你会很高兴的哦。。。。。呵呵呵呵呵俄
flex air 博客管理系统 学习用的例子
flexair网页截图工具flexair网页截图工具flexair网页截图工具flexair网页截图工具
flex air 桌面系统一个完整的桌面开发的例子,供大家分享学习。
flex air 单机版俄罗斯方块 小游戏 flexbuilder项目文件
学习flex air的基础书,挺好用的,初学的可以下载来看看
费了好大力气才找到的,希望对大家有帮助。从安装等简单的东西,到使用本地数据库,网络,本地化等高级的功能。
flex air 导出excel表格(这个不支持中文)。。。。。。
是一个linux环境下运行的flex air例子,有源码.
一本介绍富媒体软件开发的实用教程,详细地讲解了怎么用flex 来开发AIR应用程序,很实用的哦
Flex Air音乐播放器源码,使用的是Flex Builder3版本!!!
基于ArcGIS Flex API开发Flex AIR Mobile应用
使用 Adobe Flex 3 开发 Adobe AIR 1.1 应用程序
《flash+flex+air移动开发入门经典——适用于android、ios和blackberry》 第1章 flash、flex和air简介 1 1.1 adobe flash 1 1.2 actionscript 3.0 2 1.2.1 ecmascript 2 1.2.2 关键概念 3 1.3 flex框架 11 ...
主要是用于flex AIR工程远程自动检测新版本更新功能。 主要对比是<version>v4中version的版本,如v4
flex Air 打包,找了好久,才找到和大家共享一下。
NULL 博文链接:https://dzlg.iteye.com/blog/734992
程序缘 Flex AIR之旅-第六章 编写用户登录界面,用于学习借鉴的Flex Air的工程源码,导入flash builder4.6即可。已实现一般C/S结构展现界面的实现,如菜单、快捷工具栏、主窗口等。
使用Flex SDK创建第一个桌面AIR应用程序