window.runtime 属性window.runtime.flash.desktop.DockIcon
继承DockIcon Inheritance InteractiveIcon Inheritance Icon Inheritance EventDispatcher Inheritance Object

DockIcon 类表示 MacOS X® 样式的停靠图标。

可以使用 DockIcon 类来更改标准图标的外观,例如使图标具有动画效果或添加信息性图形。也可以向停靠图标菜单中添加项目。您添加的菜单项将显示在标准菜单项之上。

无法创建 DockIcon 类的实例。从 NativeApplication.icon 获取表示操作系统停靠图标的对象。

不是所有操作系统都有停靠图标。检查 NativeApplication.supportsDockIcon 以确定在当前系统上是否支持停靠图标。如果支持停靠图标,则 NativeApplication.icon 属性为 DockIcon 类型。否则,NativeApplication.icon 的类型为 InteractiveIcon 的另一个子类,通常为 SystemTrayIcon。

重要说明:在 AIR 不支持停靠图标的操作系统上尝试对 NativeApplication.icon 对象调用 DockIcon 类方法会生成运行时异常。

查看示例

另请参见

NativeApplication.icon
NativeApplication.supportsDockIcon
SystemTrayIcon


属性
 属性定义方
  bitmaps : Array
作为不同大小的 BitmapData 对象数组的图标图像。
DockIcon
 Inheritedconstructor : Object
对类对象或给定对象实例的构造函数的引用。
Object
  height : int
[只读 (read-only)] 图标的当前显示高度,以像素为单位。
DockIcon
  menu : NativeMenu
此停靠图标的系统提供菜单。
DockIcon
 Inheritedprototype : Object
[静态] 对类或函数对象的原型对象的引用。
Object
  width : int
[只读 (read-only)] 图标的当前显示宽度,以像素为单位。
DockIcon
公共方法
 方法定义方
 Inherited
addEventListener(type:String, listener:Function, useCapture:Boolean = false, priority:int = 0, useWeakReference:Boolean = false):void
使用 EventDispatcher 对象注册事件侦听器对象,以使侦听器能够接收事件通知。
EventDispatcher
  
bounce(priority:String = "informational"):void
通知用户已发生了可能需要引起注意的事件。
DockIcon
 Inherited
dispatchEvent(event:Event):Boolean
将事件调度到事件流中。
EventDispatcher
 Inherited
hasEventListener(type:String):Boolean
检查 EventDispatcher 对象是否为特定事件类型注册了任何侦听器。
EventDispatcher
 Inherited
hasOwnProperty(name:String):Boolean
指示对象是否已经定义了指定的属性。
Object
 Inherited
isPrototypeOf(theClass:Object):Boolean
指示 Object 类的实例是否在指定为参数的对象的原型链中。
Object
 Inherited
propertyIsEnumerable(name:String):Boolean
指示指定的属性是否存在、是否可枚举。
Object
 Inherited
removeEventListener(type:String, listener:Function, useCapture:Boolean = false):void
从 EventDispatcher 对象中删除侦听器。
EventDispatcher
 Inherited
setPropertyIsEnumerable(name:String, isEnum:Boolean = true):void
设置循环操作动态属性的可用性。
Object
 Inherited
toString():String
返回指定对象的字符串表示形式。
Object
 Inherited
valueOf():Object
返回指定对象的原始值。
Object
 Inherited
willTrigger(type:String):Boolean
检查是否用此 EventDispatcher 对象或其任何始祖为指定事件类型注册了事件侦听器。
EventDispatcher
事件
 事件 摘要 定义方
 InheritedFlash Player 或 AIR 应用程序获得操作系统焦点并变为活动状态时调度。EventDispatcher
 InheritedFlash Player 或 AIR 应用程序失去操作系统焦点并变为非活动状态时调度。EventDispatcher
属性详细信息
bitmaps属性
bitmaps:Array  [读写]

作为不同大小的 BitmapData 对象数组的图标图像。

当在给定的操作系统上下文中显示图标时,将使用数组中最接近所显示大小的位图(必要时进行缩放)。常用的大小包括 16x16、32x32、48x48 和 128x128。(在不远的将来,某些操作系统将可以使用 512x512 像素的图标。)

在某些上下文中,如果没有为 bitmaps 属性分配任何数据,则操作系统可以使用默认的系统图标。在其他上下文中,不显示图标。

若要设置或更改图标外观,请将 BitmapData 对象数组分配给 bitmaps 属性:

  icon.bitmaps = new Array(icon16x16.bitmapData, icon128x128.bitmapData);
  

直接修改 bitmaps 数组没有任何效果。

若要清除图标图像,请为 bitmaps 属性分配一个空数组。

注意:在为图标加载图像文件时,PNG 文件格式通常提供最佳 Alpha 混合。GIF 格式只支持打开或关闭透明度(无混合)。JPG 格式完全不支持透明度。

height属性 
height:int  [只读 (read-only)]

图标的当前显示高度,以像素为单位。

某些图标上下文支持动态大小。height 属性指示从当前上下文的 bitmaps 数组中选择的图标的高度。如果操作系统已缩放了该图标,则实际显示高度可能会有所不同。

menu属性 
menu:NativeMenu  [读写]

此停靠图标的系统提供菜单。

菜单中的任何项目都将显示在标准项目之上。标准项目无法修改或删除。


示例
下面的示例将一个项目添加到停靠图标菜单:
 
function createDockIconMenu(){
    if(air.NativeApplication.supportsDockIcon){                
        var dockIcon = air.NativeApplication.nativeApplication.icon;
        
        var dockMenu = new air.NativeMenu();
        var command = dockMenu.addItem(new air.NativeMenuItem("Command"));
        command.addEventListener(air.Event.SELECT, onCommand);
        
        dockIcon.menu = dockMenu;
    }
}

function onCommand(event){
     //do command...
}
width属性 
width:int  [只读 (read-only)]

图标的当前显示宽度,以像素为单位。

某些图标上下文支持动态大小。width 属性指示从当前上下文的 bitmaps 数组中选择的图标的宽度。如果操作系统已缩放了该图标,则实际显示宽度可能会有所不同。

方法详细信息
bounce()方法
function bounce(priority:String = "informational"):void

通知用户已发生了可能需要引起注意的事件。

当且仅当应用程序处于后台时,调用此方法将回弹停靠图标。如果 priorityNotificationType.Informational,则图标将回弹一次。如果 priorityNotificationType.Critical,则图标将一直回弹,直到应用程序处于前景中。

参数

priority:String (default = "informational") — 回弹停靠的紧急程度。

另请参见


示例

在下例中,在用户激活应用程序之前,将一直回弹停靠图标:

 if(air.NativeApplication.supportsDockIcon){
     var dockIcon = air.NativeApplication.nativeApplication.icon;
     dockIcon.bounce(air.NotificationType.CRITICAL);
 }
 
示例
DockIconExample.as

下例加载了一系列图像,通过停靠图标菜单启动计时器后,将使图标图像具有动画效果。(要使示例能够运行,必须提供一组图标图像并更改 imageURLs 数组中的 URL。)

 <script>
        var imageURLs =  ['gfx/frame01.png',
                          'gfx/frame02.png',
                          'gfx/frame03.png',
                          'gfx/frame04.png'];
        
         var images = new Array();
         var animTimer;
                                        
         function initAnimatedDockIcon()
        {
            air.NativeApplication.nativeApplication.autoExit = false;
            loadImages();
            addMenu();
                        
            window.nativeWindow.visible = false;
        }
        
        function addMenu(){
            var menu = new air.NativeMenu();
            var start = menu.addItem(new air.NativeMenuItem("Start animation"));
            var stop = menu.addItem(new air.NativeMenuItem("Stop animation"));
            start.addEventListener(air.Event.SELECT, startTimer);
            stop.addEventListener(air.Event.SELECT, stopTimer);
            
            var dockIcon =    air.NativeApplication.nativeApplication.icon;
            dockIcon.menu = menu;
        }
        
        function startTimer(event){
            clearInterval(animTimer);
            animTimer = setInterval(advanceFrame, 100);
        }

        function stopTimer(event){
            clearInterval(animTimer);
        }

        var currentFrame = 0;
        function advanceFrame(event){
            if(currentFrame < images.length - 1){
                currentFrame++;
            } else {
                currentFrame = 0;
            }
            air.trace(currentFrame);
            air.NativeApplication.nativeApplication.icon.bitmaps = [images[currentFrame]];
        }
        

        function loadImages(event){
            if(event != null){
                images.push(event.target.content.bitmapData);
            }
            if(imageURLs.length > 0){
                var urlString = imageURLs.pop();
                var loader = new air.Loader();
                loader.contentLoaderInfo.addEventListener(air.Event.COMPLETE, loadImages, false, 0, true);
                loader.load(new air.URLRequest(urlString));
            } else {
                animTimer = setInterval(advanceFrame, 100);
            }
        }
</script>