//----------------MyPopUp.mxml------------------
<?xml version="1.0" encoding="utf-8"?> <mx:Application xmlns:mx="http://www.adobe.com/2006/mxml"> <mx:Script> <![CDATA[ import mx.managers.PopUpManager; internal function doShow():void { var myWin:MyWindow = new MyWindow(); myWin.x = 0; myWin.y = 0; PopUpManager.addPopUp(myWin, myPanel, true); PopUpManager.centerPopUp(myWin); } ]]> </mx:Script> <mx:Panel width="500" height="300" id="myPanel"> <mx:Button label="显示弹出" click="doShow()" width="80" height="30" /> </mx:Panel> </mx:Application> //---------------MyWindow.mxml------------------ <?xml version="1.0" encoding="utf-8"?> <mx:Panel width="300" height="200" xmlns:mx="http://www.adobe.com/2006/mxml"> <mx:Script> <![CDATA[ import mx.managers.PopUpManager; internal function doClose():void { PopUpManager.removePopUp(this); } ]]> </mx:Script> <!-- 先定义一个组件,再new它,popup它,关闭它 --> <mx:Panel width="100%" height="100%"> <mx:Text text="测试文本" width="100%" height="50" /> <mx:ControlBar label="控制"> <mx:Button label="关闭" width="60" height="30" click="doClose()" /> </mx:ControlBar> </mx:Panel> </mx:Panel> //--------------------注意-------------------------- 1 PopUpManager的写法,Up的U字母是大写。mx.managers,注意是复数managers 2 PopUpManager.centerPopUp()的调用应该放在addPopUp或createPopUp()函数之后 |