Packageflash.desktop
Classpublic class DockIcon
InheritanceDockIcon Inheritance InteractiveIcon Inheritance Icon Inheritance EventDispatcher Inheritance Object

Language version: ActionScript 3.0
Runtime version: AIR 1.0

The DockIcon class represents the Mac OS X®-style dock icon.

AIR profile support: This feature is supported on all desktop operating systems, but it is not supported on mobile devices or AIR for TV devices. You can test for support at run time using the NativeApplication.supportsDockIcon property. See AIR Profile Support for more information regarding API support across multiple profiles.

You can use the DockIcon class to change the appearance of the standard icon; for example, to animate the icon or add informational graphics. You can also add items to the dock icon menu. The menu items that you add are displayed above the standard menu items.

An instance of the DockIcon class cannot be created. Get the object representing the operating system dock icon from NativeApplication.icon.

Not all operating systems have dock icons. Check NativeApplication.supportsDockIcon to determine whether dock icons are supported on the current system. If dock icons are supported, the NativeApplication.icon property is of type DockIcon. Otherwise, the type of NativeApplication.icon is another subclass of InteractiveIcon, typically SystemTrayIcon.

Important: Attempting to call a DockIcon class method on the NativeApplication.icon object on an operating system for which AIR does not support dock icons generates a run-time exception.

View the examples.

See also

flash.desktop.NativeApplication.icon
flash.desktop.NativeApplication.supportsDockIcon
flash.desktop.SystemTrayIcon


Public Properties
 PropertyDefined by
  bitmaps : Array
DockIcon
 Inheritedconstructor : Object
A reference to the class object or constructor function for a given object instance.
Object
  height : int
[read-only] The current display height of the icon in pixels.
DockIcon
  menu : NativeMenu
The system-supplied menu of this dock icon.
DockIcon
 Inheritedprototype : Object
[static] A reference to the prototype object of a class or function object.
Object
  width : int
[read-only] The current display width of the icon in pixels.
DockIcon
Public Methods
 MethodDefined by
 Inherited
addEventListener(type:String, listener:Function, useCapture:Boolean = false, priority:int = 0, useWeakReference:Boolean = false):void
Registers an event listener object with an EventDispatcher object so that the listener receives notification of an event.
EventDispatcher
  
bounce(priority:String = "informational"):void
Notifies the user that an event has occurred that may require attention.
DockIcon
 Inherited
Dispatches an event into the event flow.
EventDispatcher
 Inherited
Checks whether the EventDispatcher object has any listeners registered for a specific type of event.
EventDispatcher
 Inherited
Indicates whether an object has a specified property defined.
Object
 Inherited
Indicates whether an instance of the Object class is in the prototype chain of the object specified as the parameter.
Object
 Inherited
Indicates whether the specified property exists and is enumerable.
Object
 Inherited
removeEventListener(type:String, listener:Function, useCapture:Boolean = false):void
Removes a listener from the EventDispatcher object.
EventDispatcher
 Inherited
Sets the availability of a dynamic property for loop operations.
Object
 Inherited
Returns the string representation of this object, formatted according to locale-specific conventions.
Object
 Inherited
Returns the string representation of the specified object.
Object
 Inherited
Returns the primitive value of the specified object.
Object
 Inherited
Checks whether an event listener is registered with this EventDispatcher object or any of its ancestors for the specified event type.
EventDispatcher
Events
 EventSummaryDefined by
 Inherited [broadcast event] Dispatched when the Flash Player or AIR application gains operating system focus and becomes active.EventDispatcher
 Inherited [broadcast event] Dispatched when the Flash Player or AIR application operating loses system focus and is becoming inactive.EventDispatcher
Property detail
bitmapsproperty
bitmaps:Array  [read-write]Implementation
    public function get bitmaps():Array
    public function set bitmaps(value:Array):void
heightproperty 
height:int  [read-only]

Runtime version: AIR 1.0

The current display height of the icon in pixels.

Some icon contexts support dynamic sizes. The height property indicates the height of the icon chosen from the bitmaps array for the current context. The actual display height may be different if the operating system has scaled the icon.

Implementation
    public function get height():int
menuproperty 
menu:NativeMenu  [read-write]

Language version: ActionScript 3.0
Runtime version: AIR 1.0

The system-supplied menu of this dock icon.

Any items in the menu are displayed above the standard items. The standard items cannot be modified or removed.

Implementation
    public function get menu():NativeMenu
    public function set menu(value:NativeMenu):void

Example
The following example adds an item to the dock icon menu:
 import flash.desktop.NativeApplication;
 import flash.events.Event;
 
private function createDockIconMenu():void{
    if(NativeApplication.supportsDockIcon){				
		var dockIcon:DockIcon = NativeApplication.nativeApplication.icon as DockIcon;
		
		var dockMenu:NativeMenu = new NativeMenu();
		var command:NativeMenuItem = dockMenu.addItem(new NativeMenuItem("Command"));
		command.addEventListener(Event.SELECT, onCommand);
		
		dockIcon.menu = dockMenu;
	}
}

 private function onCommand(event:Event):void{
 	//do command...
 }

widthproperty 
width:int  [read-only]

Runtime version: AIR 1.0

The current display width of the icon in pixels.

Some icon contexts support dynamic sizes. The width property indicates the width of the icon chosen from the bitmaps array for the current context. The actual display width may be different if the operating system has scaled the icon.

Implementation
    public function get width():int
Method detail
bounce()method
public function bounce(priority:String = "informational"):void

Language version: ActionScript 3.0
Runtime version: AIR 1.0

Notifies the user that an event has occurred that may require attention.

Calling this method bounces the dock icon if, and only if, the application is in the background. If the priority is NotificationType.Informational then the icon bounces once. If the priority is NotificationType.Critical then the icon bounces until the application is brought to the foreground.

Parameters
priority:String (default = "informational") — The urgency with which to bounce the dock.

See also


Example
The following example bounces the dock icon until the user activates the application:
 import flash.display.DockIcon;
 import flash.display.NotificationType;
 import flash.desktop.NativeApplication;

 if(NativeApplication.supportsDockIcon){
     var dockIcon:DockIcon = NativeApplication.nativeApplication.icon As DockIcon;
 	dockIcon.bounce(NotificationType.CRITICAL);
 }

Examples
examples\DockIconExample
The following example loads a sequence of images and, when the timer is started with the dock icon menu, animates the icon image. (For the example to work, you must supply a set of icon images and change the URLs in the imageURLs array.)

 package {
    import flash.desktop.DockIcon;
	import flash.desktop.NativeApplication;
	import flash.display.Loader;
	import flash.display.NativeMenu;
	import flash.display.NativeMenuItem;
	import flash.display.Sprite;
	import flash.events.Event;
	import flash.events.TimerEvent;
	import flash.net.URLRequest;
	import flash.utils.Timer;

	public class AnimatedDockIcon extends Sprite
	{
		private var imageURLs:Array =  ['gfx/frame01.png',
										'gfx/frame02.png',
										'gfx/frame03.png',
										'gfx/frame04.png'];
		
		private var images:Array = new Array();
		private var animTimer:Timer = new Timer(100);
										
		public function AnimatedDockIcon()
		{
			NativeApplication.nativeApplication.autoExit = false;
			
			addEventListener(Event.COMPLETE, loadImages);
			loadImages();
			
			animTimer.addEventListener(TimerEvent.TIMER,advanceFrame);
			addMenu();
			stage.nativeWindow.close();
		}
		
		private function addMenu():void{
			var menu:NativeMenu = new NativeMenu();
			var start:NativeMenuItem = menu.addItem(new NativeMenuItem("Start animation"));
			var stop:NativeMenuItem = menu.addItem(new NativeMenuItem("Stop animation"));
			start.addEventListener(Event.SELECT, startTimer);
			stop.addEventListener(Event.SELECT, stopTimer);
			
			var dockIcon:DockIcon =	NativeApplication.nativeApplication.icon as DockIcon;
			dockIcon.menu = menu;
		}
		
		private function startTimer(event:Event):void{
			animTimer.start();
		}

		private function stopTimer(event:Event):void{
			animTimer.stop();
		}

		private var currentFrame:int = 0;
		private function advanceFrame(event:Event):void{
			if(currentFrame < images.length){
				currentFrame++;
			} else {
				currentFrame = 0;
			}
			NativeApplication.nativeApplication.icon.bitmaps = [images[currentFrame]];
		}
		

		private function loadImages(event:Event = null):void{
        	if(event != null){
        		images.push(event.target.content.bitmapData);
        	}
        	if(imageURLs.length > 0){
        		var urlString:String = imageURLs.pop();
        		var loader:Loader = new Loader();
        		loader.contentLoaderInfo.addEventListener(Event.COMPLETE, loadImages, false, 0, true);
				loader.load(new URLRequest(urlString));
        	} else {
        		var complete:Event = new Event(Event.COMPLETE,false,false);
        		dispatchEvent(complete);
        	}
        }
	}
}