饭否1.7发布了,增加的最小化到系统托盘的功能部分代码分享:
- /**关闭&最小化到托盘按钮点击事件处理*/
- public function clickWindowHandler(e:Event):void {
- if (e.target == minBtn) {
- createIcon();
- stage.nativeWindow.visible=false;
- }
- if (e.target == closeBtn) {
- NativeApplication.nativeApplication.exit();
- }
- }
- /**从后台再现窗体*/
- public function reappear(e:ScreenMouseEvent=null):void{
- stage.nativeWindow.visible=true;
- removeIcon();
- }
- /**创建托盘图标*/
- public function createIcon():void
- {
- NativeApplication.nativeApplication.autoExit = false;
- var icon:Loader = new Loader();
- var iconMenu:NativeMenu = new NativeMenu();
- var exitCommand:NativeMenuItem = iconMenu.addItem(new NativeMenuItem("退出"));
- exitCommand.addEventListener(Event.SELECT, function(event:Event):void
- {
- NativeApplication.nativeApplication.icon.bitmaps = [];
- NativeApplication.nativeApplication.exit();
- }
- );
- if (NativeApplication.supportsSystemTrayIcon)
- {
- NativeApplication.nativeApplication.autoExit = false;
- icon.contentLoaderInfo.addEventListener(Event.COMPLETE, iconLoadComplete);
- icon.load(new URLRequest("resource/icons/i16.png"));
- var systray:SystemTrayIcon=NativeApplication.nativeApplication.icon as SystemTrayIcon;
- systray.tooltip = "饭否AIR客户端";
- systray.menu = iconMenu;
- systray.addEventListener(MouseEvent.CLICK,reappear);
- }
- if (NativeApplication.supportsDockIcon)
- {
- icon.contentLoaderInfo.addEventListener(Event.COMPLETE,iconLoadComplete);
- icon.load(new URLRequest("resource/icons/i128.png"));
- var dock:DockIcon = NativeApplication.nativeApplication.icon as DockIcon;
- dock.menu = iconMenu;
- dock.addEventListener(MouseEvent.CLICK,reappear);//这种情况我没法测试 也不知道会不会有问题,所以先Alpha一下
- }
- }
- /**移除托盘图标*/
- public function removeIcon():void
- {
- NativeApplication.nativeApplication.icon.bitmaps = [];
- }
- private function iconLoadComplete(event:Event):void
- {
- NativeApplication.nativeApplication.icon.bitmaps = [event.target.content.bitmapData];
- }
AIR开发和AS开发有联系吗?
应该有. -_-|