如何在没有顶级窗口的情况下显示警告框?

时间:2011-01-27 05:22:42

标签: actionscript-3 air

Adob​​e AIR提供Alert.show()。但是,如果没有像典型托盘示例中那样的顶级窗口(“示例:创建没有窗口的应用程序”),这似乎会失败:

http://livedocs.adobe.com/flex/3/html/taskbar_1.html

我无法在这种情况下使Alert.show()工作。似乎没有警报()。

在没有重新发明轮子的情况下,有没有办法在这种情况下显示警告提示(模态或非模态)?

示例AIR托盘应用程序框架:

<?xml version="1.0" encoding="utf-8"?>
<s:WindowedApplication xmlns:fx="http://ns.adobe.com/mxml/2009"
        xmlns:s="library://ns.adobe.com/flex/spark"
        xmlns:mx="library://ns.adobe.com/flex/mx"
                       windowComplete="init(event)" visible="false">
 <fx:Script>
  <![CDATA[
   import flash.events.InvokeEvent;

   import mx.controls.Alert;
   import mx.events.CloseEvent;

   import mx.events.AIREvent;

   // As windows does not work without icon, we MUST embed it.
   // Stories told differently on the net are void.
   [Embed(source="icons/AIRApp_16.png")]  private var img16:Class;
   [Embed(source="icons/AIRApp_32.png")]  private var img32:Class;
   [Embed(source="icons/AIRApp_48.png")]  private var img48:Class;
   [Embed(source="icons/AIRApp_128.png")] private var img128:Class;

   private function helloworld(evt:Event):void {
    //This does not work
    Alert.show("hello world");
   }

   private function closer(e:CloseEvent):void
   {
    if (e.detail == Alert.YES) {
     NativeApplication.nativeApplication.icon.bitmaps = [];
     NativeApplication.nativeApplication.exit();
    }
   }

   private function doexit(event:Event):void {
    //This does not work either
    Alert.show("Really?","Exit application", Alert.YES | Alert.NO | Alert.NONMODAL, null, closer, null, 3);
   }

   protected function init(event:AIREvent):void {

    NativeApplication.nativeApplication.autoExit = false;

    var iconMenu:NativeMenu = new NativeMenu();

    var exitCommand:NativeMenuItem = iconMenu.addItem(new NativeMenuItem("Exit"));
    exitCommand.addEventListener(Event.SELECT, doexit);

    NativeApplication.nativeApplication.icon.bitmaps = [new img16, new img32, new img48, new img128];

    if (NativeApplication.supportsSystemTrayIcon) {

     var systray:SystemTrayIcon = NativeApplication.nativeApplication.icon as SystemTrayIcon;
     systray.tooltip = "Monitor Application";
     systray.menu = iconMenu;
     systray.addEventListener(ScreenMouseEvent.CLICK, helloworld);

    } else if (NativeApplication.supportsDockIcon) {

     var dock:DockIcon = NativeApplication.nativeApplication.icon as DockIcon;
     dock.menu = iconMenu;
     NativeApplication.nativeApplication.addEventListener(InvokeEvent.INVOKE, helloworld);
    }
   }

  ]]>
 </fx:Script>
 <fx:Declarations>
  <!-- Platzieren Sie nichtvisuelle Elemente (z. B. Dienste, Wertobjekte) hier -->
 </fx:Declarations>
</s:WindowedApplication>

注意“visible = false”必须保留,即使这是造成麻烦的原因。

1 个答案:

答案 0 :(得分:0)

没有。 Air和Flex中的应用程序是您的根级对象。所有警报都必须是该对象的子级。如果父级有visible = false,则不会看到任何孩子。

对不起。

在调用Alert.show()之前,您是否考虑过将可见性设置为true?