Flex治理多个弹出窗口
Flex管理多个弹出窗口??? var pop:Panel (PopUpManager.createPopUp(this, mx.containers.Panel,false,
Flex管理多个弹出窗口
??? var pop:Panel = (PopUpManager.createPopUp(this, mx.containers.Panel,
false, PopUpManagerChildList.POPUP) as Panel);
访问并改变多个对话框需要有对这些弹出控件的引用,但是PopUpManager.addPopUp 方法并有提供这个引用。因此,你需要使用PopUpManager 类的createPopUp 方法.这个方法返回一个被创建对象的引用,这样可以将这个引用添加到一个数组里面去。在一个大的应用程序里面,这样的数组应该申明成全局可访问的,通过public static 修饰,同时使用getter 和setter 方法使得所有组件在需要时都可访问生成的弹出物。例如:
createPopUp 方法需要传入一个父容器引用的参数,即生成弹出物的类,和一个Boolean 值来判别弹出得对话框是否为模式化的,然后返回被创建对象的引用
?
Java代码
<mx:Application??xmlns:mx="http://www.adobe.com/2006/mxml"??layout="absolute">??????<mx:HBox?xmlns:mx="http://www.adobe.com/2006/mxml"?width="600"??height="500"?creationComplete="addDialog()">??<mx: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);??????}??????]]>??</mx:Script>??<mx:ComboBox?id="selectDialog"?change="returnDialog()">??????<mx:dataProvider>??????????<mx:Array>??????????<mx:Number>0</mx:Number>??????????<mx:Number>1</mx:Number>??????????<mx:Number>2</mx:Number>??????????</mx:Array>??????</mx:dataProvider>??</mx:ComboBox>??<mx:Panel>??????<mx:LinkButton?label="Button"/>??</mx:Panel>??<mx:Panel>??????<mx:LinkButton?label="Button"/>??</mx:Panel>??</mx:HBox>??</mx:Application>