首页
学习
活动
专区
圈层
工具
发布
社区首页 >问答首页 >如何显示没有顶层窗口的警告框?

如何显示没有顶层窗口的警告框?
EN

Stack Overflow用户
提问于 2011-01-27 13:22:42
回答 1查看 3K关注 0票数 0

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

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

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

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

空气托盘应用程序框架示例:

代码语言:javascript
复制
<?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“,即使这是导致问题的原因,也必须保留它。

EN

回答 1

Stack Overflow用户

回答已采纳

发布于 2011-01-27 13:28:59

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

抱歉的。

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

票数 0
EN
页面原文内容由Stack Overflow提供。腾讯云小微IT领域专用引擎提供翻译支持
原文链接:

https://stackoverflow.com/questions/4813019

复制
相关文章

相似问题

领券
问题归档专栏文章快讯文章归档关键词归档开发者手册归档开发者手册 Section 归档