| 包 | flash.desktop |
| 类 | public class DockIcon |
| 继承 | DockIcon InteractiveIcon Icon EventDispatcher Object |
| 语言版本: | ActionScript 3.0 |
| 运行时版本: | AIR 1.0 |
可以使用 DockIcon 类来更改标准图标的外观,例如使图标具有动画效果或添加信息性图形。也可以向停靠图标菜单中添加项目。您添加的菜单项将显示在标准菜单项之上。
无法创建 DockIcon 类的实例。从 NativeApplication.icon 获取表示操作系统停靠图标的对象。
不是所有操作系统都有停靠图标。检查 NativeApplication.supportsDockIcon 以确定在当前系统上是否支持停靠图标。如果支持停靠图标,则 NativeApplication.icon 属性为 DockIcon 类型。否则,NativeApplication.icon 的类型为 InteractiveIcon 的另一个子类,通常为 SystemTrayIcon。
重要说明:在 AIR 不支持停靠图标的操作系统上尝试对 NativeApplication.icon 对象调用 DockIcon 类方法会生成运行时异常。
另请参见
| 属性 | 定义方 | ||
|---|---|---|---|
作为不同大小的 BitmapData 对象数组的图标图像。 | DockIcon | ||
![]() | constructor : Object
对类对象或给定对象实例的构造函数的引用。 | Object | |
[只读 (read-only)] 图标的当前显示高度,以像素为单位。 | DockIcon | ||
此停靠图标的系统提供菜单。 | DockIcon | ||
![]() | prototype : Object [静态]
对类或函数对象的原型对象的引用。 | Object | |
[只读 (read-only)] 图标的当前显示宽度,以像素为单位。 | DockIcon | ||
| 方法 | 定义方 | ||
|---|---|---|---|
![]() | addEventListener(type:String, listener:Function, useCapture:Boolean = false, priority:int = 0, useWeakReference:Boolean = false):void 使用 EventDispatcher 对象注册事件侦听器对象,以使侦听器能够接收事件通知。 | EventDispatcher | |
通知用户已发生了可能需要引起注意的事件。 | DockIcon | ||
![]() | 将事件调度到事件流中。 | EventDispatcher | |
![]() | 检查 EventDispatcher 对象是否为特定事件类型注册了任何侦听器。 | EventDispatcher | |
![]() |
指示对象是否已经定义了指定的属性。 | Object | |
![]() |
指示 Object 类的实例是否在指定为参数的对象的原型链中。 | Object | |
![]() |
指示指定的属性是否存在、是否可枚举。 | Object | |
![]() | 从 EventDispatcher 对象中删除侦听器。 | EventDispatcher | |
![]() |
设置循环操作动态属性的可用性。 | Object | |
![]() |
返回指定对象的字符串表示形式。 | Object | |
![]() |
返回指定对象的原始值。 | Object | |
![]() | 检查是否用此 EventDispatcher 对象或其任何始祖为指定事件类型注册了事件侦听器。 | EventDispatcher | |
| 属性 |
bitmaps:Array [读写] | 运行时版本: | AIR 1.0 |
作为不同大小的 BitmapData 对象数组的图标图像。
当在给定的操作系统上下文中显示图标时,将使用数组中最接近所显示大小的位图(必要时进行缩放)。常用的大小包括 16x16、32x32、48x48 和 128x128。(在不远的将来,某些操作系统将可以使用 512x512 像素的图标。)
在某些上下文中,如果没有为 bitmaps 属性分配任何数据,则操作系统可以使用默认的系统图标。在其他上下文中,不显示图标。
若要设置或更改图标外观,请将 BitmapData 对象数组分配给 bitmaps 属性:
icon.bitmaps = new Array(icon16x16.bitmapData, icon128x128.bitmapData);
直接修改 bitmaps 数组没有任何效果。
若要清除图标图像,请为 bitmaps 属性分配一个空数组。
注意:在为图标加载图像文件时,PNG 文件格式通常提供最佳 Alpha 混合。GIF 格式只支持打开或关闭透明度(无混合)。JPG 格式完全不支持透明度。
public function get bitmaps():Array public function set bitmaps(value:Array):void| 属性 |
height:int [只读 (read-only)] | 运行时版本: | AIR 1.0 |
图标的当前显示高度,以像素为单位。
某些图标上下文支持动态大小。height 属性指示从当前上下文的 bitmaps 数组中选择的图标的高度。如果操作系统已缩放了该图标,则实际显示高度可能会有所不同。
public function get height():int| 属性 |
menu:NativeMenu [读写] | 语言版本: | ActionScript 3.0 |
| 运行时版本: | AIR 1.0 |
此停靠图标的系统提供菜单。
菜单中的任何项目都将显示在标准项目之上。标准项目无法修改或删除。
public function get menu():NativeMenu public function set menu(value:NativeMenu):voidimport 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...
}| 属性 |
width:int [只读 (read-only)] | 运行时版本: | AIR 1.0 |
图标的当前显示宽度,以像素为单位。
某些图标上下文支持动态大小。width 属性指示从当前上下文的 bitmaps 数组中选择的图标的宽度。如果操作系统已缩放了该图标,则实际显示宽度可能会有所不同。
public function get width():int| () | 方法 |
public function bounce(priority:String = "informational"):void| 语言版本: | ActionScript 3.0 |
| 运行时版本: | AIR 1.0 |
通知用户已发生了可能需要引起注意的事件。
当且仅当应用程序处于后台时,调用此方法将回弹停靠图标。如果 priority 为 NotificationType.Informational,则图标将回弹一次。如果 priority 为 NotificationType.Critical,则图标将一直回弹,直到应用程序处于前景中。
参数
priority:String (default = "informational") — 回弹停靠的紧急程度。 |
另请参见
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);
}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);
}
}
}
}