不同的选项卡的不同组弹出窗口

时间:2011-10-03 22:22:29

标签: flex tabs popup

假设我有一个标签式应用程序。我可以让弹出窗口仅出现在给定的选项卡中吗?因此,如果我更改选项卡,则会隐藏相关的弹出窗口(-s)。到目前为止,我还没有找到任何解决方案。所以任何想法都将非常感激:)

1 个答案:

答案 0 :(得分:1)

您必须自己处理不同的弹出窗口:Flex只能添加和删除将显示在应用程序最顶层的弹出窗口。

编辑:这是一个小样本。

<?xml version="1.0"?>
<!-- containers\navigators\TNSimple.mxml -->
<s:Application
    xmlns:fx="http://ns.adobe.com/mxml/2009" 
    xmlns:mx="library://ns.adobe.com/flex/mx" 
    xmlns:s="library://ns.adobe.com/flex/spark"
    creationComplete="onCreationComplete()"
    >
    <fx:Script>
        <![CDATA[

            import mx.managers.PopUpManager;
            import spark.components.TitleWindow;
            import mx.events.IndexChangedEvent;

            private var popups:Array = [];

            private function onCreationComplete():void
            {
                popups = [[],[],[]];
            }

            private function createPopup():void
            {
                var foo:TitleWindow = new TitleWindow();

                PopUpManager.addPopUp(foo, this);

                PopUpManager.centerPopUp(foo);

                popups[nav.selectedIndex].push(foo);
            }

            private function onTabChange(event:IndexChangedEvent):void
            {
                var i:int;

                var oldArray:Array = popups[event.oldIndex];
                for (i = 0; i < oldArray.length; i++) {
                    PopUpManager.removePopUp(oldArray[i]);
                }

                var newArray:Array = popups[event.newIndex];
                for (i = 0; i < newArray.length; i++) {
                    PopUpManager.addPopUp(newArray[i], this);
                }
            }
        ]]>
    </fx:Script>
    <mx:TabNavigator id="nav" borderStyle="solid" x="50" y="50" change="onTabChange(event)">
        <mx:VBox label="Accounts" 
            width="300" 
            height="150">
            <mx:Button label="pop" click="createPopup()"/>
        </mx:VBox>

        <mx:VBox label="Stocks" 
            width="300" 
            height="150">
            <mx:Button label="pop" click="createPopup()"/>
        </mx:VBox>

        <mx:VBox label="Futures" 
            width="300" 
            height="150">
            <mx:Button label="pop" click="createPopup()"/>
        </mx:VBox>   
    </mx:TabNavigator>
</s:Application>