想要管理多个弹出的页面,就得获得这些页面的id引用。虽然PopUpManager.addPopUp可以创建弹出页面,但是这个方法没有返回值。

幸好,PopUpManager.createPopUp方法有返回值,返回的就是当前弹出的页面对象。

如果有很多弹出页面,那么就用Array去存储每个弹出页面的对象,以方便将来的使用,


示例 代码如下:


<?xml version="1.0" encoding="utf-8"?>
<s:Application xmlns:fx="http://ns.adobe.com/mxml/2009"
xmlns:s="library://ns.adobe.com/flex/spark"
xmlns:mx="library://ns.adobe.com/flex/mx"
minWidth="955" minHeight="600" creationComplete="addDialog()">
<fx:Script>
<![CDATA[
import mx.managers.PopUpManagerChildList;
import mx.controls.LinkButton;
import mx.containers.Panel;
import mx.managers.PopUpManager;

public var popUpArray:Array = new Array();

private function addDialog():void
{
var pop:Panel = (PopUpManager.createPopUp(this, mx.containers.Panel, false, PopUpManagerChildList.POPUP) as Panel);
pop.title = "First Pop Up";
pop.y = 100;
popUpArray.push(pop);
pop = (PopUpManager.createPopUp(this, mx.containers.Panel, false, PopUpManagerChildList.POPUP) as Panel);
pop.title = "Second Pop Up";
pop.y = 200;
popUpArray.push(pop);
pop = (PopUpManager.createPopUp(this, mx.containers.Panel, false, PopUpManagerChildList.POPUP) as Panel);
pop.title = "Third Pop Up";
pop.y = 300;
popUpArray.push(pop);
}

private function returnDialog():void
{
var link:LinkButton = new LinkButton();
link.label = "Hello";
(popUpArray[selectDialog.selectedIndex] as
Panel).addChild(link);
}
]]>
</fx:Script>
<mx:HBox>

<mx:ComboBox id="selectDialog" change="returnDialog()">
<mx:dataProvider>
<fx:Array>
<fx:Number>0</fx:Number>
<fx:Number>1</fx:Number>
<fx:Number>2</fx:Number>
</fx:Array>
</mx:dataProvider>
</mx:ComboBox>
<mx:Panel>
<mx:LinkButton label="Button"/>
</mx:Panel>
<mx:Panel>
<mx:LinkButton label="Button"/>
</mx:Panel>
</mx:HBox>

</s:Application>