【问题标题】:How do I show an alert box without top level window?如何在没有顶级窗口的情况下显示警报框?
【发布时间】:2011-01-27 05:22:41
【问题描述】:

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

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

我未能让 Alert.show() 在这种情况下工作。好像也没有alert()。

有没有办法在这种情况下显示警报提示(模态或非模态)而无需重新发明轮子?

示例 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”,即使这是造成问题的原因。

【问题讨论】:

  • 顺便说一句,图标可以在 AIR SDK 示例文件夹中找到。

标签: actionscript-3 air


【解决方案1】:

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

对不起。

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

【讨论】:

  • 谢谢,我正是担心这一点。显示警报时应隐藏窗口。所以我认为我只有两个选择:A)重新发明轮子,所以创建一个 myAlert 窗口类或 B)将主窗口切换为透明和无边框,这样它实际上不会显示并使用 Alert.show( )好吧,我选择变体A)然后,叹息。谢谢。
猜你喜欢
  • 1970-01-01
  • 1970-01-01
  • 1970-01-01
  • 1970-01-01
  • 1970-01-01
  • 2021-10-26
  • 2013-04-13
  • 1970-01-01
  • 1970-01-01
相关资源
最近更新 更多