2011-01-27 66 views
0

Adob​​e AIR提供Alert.show()。然而,這似乎如果像典型的例子托盤沒有頂層窗口失敗(「示例:創建不帶任何窗口的應用程序」):如何顯示沒有頂級窗口的警報框?

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

我沒能進入Alert.show()工作在這個情況下。似乎也沒有alert()。

有沒有什麼辦法可以在這種情況下顯示警報提示(模態或非模態)而不需要重新發明輪子?

如空氣托盤應用程序框架:

<?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> 

注意「可見=假」必須保留,即使這是什麼造成的麻煩。

+0

順便說一句,可以在AIR SDK示例文件夾中找到圖標。 – Tino 2011-01-27 05:26:38

回答

0

編號Air和Flex中的應用程序是您的根級對象。所有警報都必須是該對象的子項。如果父母有可見=假,則不會看到任何孩子。

對不起。

在調用Alert.show()之前,您是否考慮過將可見性設置爲true?

+0

謝謝,我很擔心。顯示Alert時窗口應該隱藏。所以我認爲我只有兩個選擇: A)要重新發明輪子,創建一個myAlert窗口類或 B)將主窗口切換爲透明和無色,這樣它幾乎不會顯示並使用警報。顯示() 那麼,我去變體A),然後,感嘆。謝謝。 – Tino 2011-01-27 15:47:32