WHAT'S NEW?
Loading...

script tray icon with air


//script tray icon with air
import flash.desktop.Icon;
import flash.desktop.SystemTrayIcon;
import flash.desktop.DockIcon;
import flash.events.MouseEvent;
import flash.events.InvokeEvent;
import flash.display.NativeWindow;
import flash.desktop.NativeApplication;
import flash.display.NativeMenu;
import flash.display.NativeMenuItem;
import flash.display.BitmapData;
var _icon:BitmapData = new myIcon();
minimize.addEventListener(MouseEvent.CLICK, toTray);

function toTray(e:MouseEvent)
{
 stage.nativeWindow.minimize();
 if (NativeApplication.supportsSystemTrayIcon)
 {
  var trayIcon:SystemTrayIcon = NativeApplication.nativeApplication.icon as SystemTrayIcon;
  trayIcon.tooltip = "My App";
  stage.nativeWindow.visible = false;
  //define tray icon - BitmapData
  NativeApplication.nativeApplication.icon.bitmaps = [_icon];
  //this creates rightclick menu
  trayIcon.menu = create_menu();
  //add listener to icon to restore window on mouse click
  trayIcon.addEventListener(MouseEvent.CLICK,undock);
 }
 else if (NativeApplication.supportsDockIcon)
 {
  //this is for dock on Mac but I didn't try it because I don't have Mac
  var dockIcon:DockIcon = NativeApplication.nativeApplication.icon as DockIcon;
  NativeApplication.nativeApplication.addEventListener(InvokeEvent.INVOKE, undock);
  dockIcon.menu = create_menu();
 }
}
function create_menu():NativeMenu
{
 //creates menu instance
 var iconMenu:NativeMenu = new NativeMenu();
 //creates menu item
 var AboutItem:NativeMenuItem = new NativeMenuItem("About");
 var showItem:NativeMenuItem = new NativeMenuItem("Show");
 var exitItem:NativeMenuItem = new NativeMenuItem("Exit");
 //adds menu items to menu
 if (NativeApplication.supportsSystemTrayIcon)
 {
  iconMenu.addItem(AboutItem);
  iconMenu.addItem(showItem);
  iconMenu.addItem(exitItem);
  showItem.addEventListener(Event.SELECT, undock);
  exitItem.addEventListener(Event.SELECT, exit);
 }
 return iconMenu;
}
//restore function
function undock(event:Event):void
{
 stage.nativeWindow.visible = true;
 NativeApplication.nativeApplication.icon.bitmaps = [];
 stage.nativeWindow.restore();
}
//exit function;
function exit(e:Event):void
{
 stage.nativeWindow.close();
}

0 komentar:

Post a Comment