Creating a pop-up window
To create a pop-up window,use the PopUpManager createPopUp() method. The createPopUp() method has the following signature:
public static createPopUp(parent:displayObject,class:Class,
modal:Boolean = false):IFlexdisplayObject
The method has the following arguments.
Argument
Description
parent
A reference to a window to pop-up over.
class
A reference to the class of object you want to create,typically a custom MXML component that implements a TitleWindow container.
modal
(Optional) A Boolean value that indicates whether the window is modal,and takes all mouse input until it is closed (true),or whether interaction is allowed with other controls while the window is displayed (false). The default value is false.
主测试文件:
01.<?xml version="1.0" encoding="utf-8"?> 02.<mx:Application xmlns:mx="http://www.adobe.com/2006/mxml" layout="absolute"> 03. <mx:Style> 04. Panel{ 05. fontSize:12px 06. } 07. Button{ 08. fontSize:12px 09. } 10. 11. </mx:Style> 12. <mx:Script> 13. <![CDATA[ 14. import mx.managers.PopUpManager; 15. import mx.containers.TitleWindow; 16. import flash.geom.Point; 17. 18. 19. private var point1:Point = new Point(); 20. private function openWin():void 21. { 22. var login:Win2=Win2(PopUpManager.createPopUp(this,Win2,true));
23. point1.x=(p1.width-login.width)/2; 24. point1.y=(p1.height-login.height)/2; 25. login.x=point1.x+35; 26. login.y=point1.y+35; 27. login.loginUserName=returnValue; 28 } 29. ]]> 30. </mx:Script> 31. <mx:Panel id="p1" x="97" y="65" width="800" height="600" layout="absolute" title="弹出窗口测试"> 32. <mx:Button id="myButton" x="257" y="302" label="Login" click="openWin()"/> 33. <mx:Text id="returnValue" text="" /> 34. </mx:Panel> 35. 36.</mx:Application>
我们通过(p1.width-login.width)/2和(p1.height-login.height)/2实现弹出窗口的居中!
PopUpManager.createPopUp( this,true) 参数:父显示对象,要显示的对象,是否为模态窗口;
Win2.mxml
程序代码
01.<?xml version="1.0" encoding="utf-8"?> 02.<mx:TitleWindow xmlns:mx="http://www.adobe.com/2006/mxml" layout="absolute" width="500" height="400"showCloseButton="true"> 03. <mx:Script> 04. <![CDATA[ 05. import mx.managers.PopUpManager; 06. import mx.containers.TitleWindow; 07. import flash.geom.Point; 08. import mx.controls.Text; 09. 10. private var point1:Point = new Point(); 11. public var loginUserName:Text; 12. public var loginUserPwd:Text; 13. private function closeWin():void 14. { 15. PopUpManager.removePopUp(this); 16. } 17. 18. private function openNewWin():void 19. { 20. login:Win1=Win1(PopUpManager.createPopUp( this,Win1,true)); 21. point1.x=(this.width-login.width)/2; 22. point1.y=(this.height-login.height)/2; 23. login.x=point1.x+5; 24. login.y=point1.y+5; 25. 26. } 27. 28. private function loginok():void 29. { 30 loginUserName.text=username.text;
31 PopUpManager.removePopUp(this); 32. } 33. ]]> 34. </mx:Script> 35. <mx:Style> 36. Label{fontSize:12px;} 37. </mx:Style> 38. <mx:Button x="139" y="258" label="open new" click="openNewWin()"/> 39. <mx:Button x="282" y="258" label="close" click="closeWin()"/> 40. <mx:Label x="139" y="87" text="用户名:"/> 41. <mx:Label x="139" y="134" text="密 码:"/> 42. <mx:TextInput x="200" y="87" id="username"/> 43. <mx:TextInput x="200" y="134" id="userpwd" displayAsPassword="true"/> 44. <mx:Button x="227" y="258" label="ok" click="loginok()"/> 45.</mx:TitleWindow>
<div class="dp-Highlighter bg_javascript"><div class="bar"><div class="tools"><b>[javascript]</b> <a href="#" class="ViewSource" title="view plain" onclick="dp.sh.Toolbar.Command('ViewSource',this);return false;">view plain</a><a href="#" class="copyToClipboard" title="copy" onclick="dp.sh.Toolbar.Command('copyToClipboard',this);return false;">copy</a><a href="#" class="PrintSource" title="print" onclick="dp.sh.Toolbar.Command('PrintSource',this);return false;">print</a><a href="#" class="About" title="?" onclick="dp.sh.Toolbar.Command('About',this);return false;">?</a><div style="position: absolute; left: 0px; top: 0px; width: 0px; height: 0px; z-index: 99;"><embed id="ZeroClipboardMovie_6" src="http://static.blog.csdn.net/scripts/ZeroClipboard/ZeroClipboard.swf" loop="false" menu="false" quality="best" bgcolor="#ffffff" width="0" height="0" name="ZeroClipboardMovie_6" align="middle" allowscriptaccess="always" allowfullscreen="false" type="application/x-shockwave-flash" pluginspage="http://www.macromedia.com/go/getflashplayer" flashvars="id=6&width=0&height=0" wmode="transparent"></div></div></div><ol start="1" class="dp-c"><li class="alt"><span><span><strong><span style=</span><span class="string">"color:#ff0000;"</span><span>>loginUserName.text=username.text;</span></strong> </span></span></li></ol></div><pre class="javascript" name="code" style="display: none;"><strong><span style="color:#ff0000;">loginUserName.text=username.text;</span></strong></pre>由于loginUserName是父窗口传过来的组件,所以此句赋值就是把子窗口的返回值传到父窗口。 <pre></pre> <div class="dp-Highlighter bg_javascript"><div class="bar"><div class="tools"><b>[javascript]</b> <a href="#" class="ViewSource" title="view plain" onclick="dp.sh.Toolbar.Command('ViewSource',this);return false;">?</a><div style="position: absolute; left: 0px; top: 0px; width: 0px; height: 0px; z-index: 99;"><embed id="ZeroClipboardMovie_7" src="http://static.blog.csdn.net/scripts/ZeroClipboard/ZeroClipboard.swf" loop="false" menu="false" quality="best" bgcolor="#ffffff" width="0" height="0" name="ZeroClipboardMovie_7" align="middle" allowscriptaccess="always" allowfullscreen="false" type="application/x-shockwave-flash" pluginspage="http://www.macromedia.com/go/getflashplayer" flashvars="id=7&width=0&height=0" wmode="transparent"></div></div></div><ol start="1" class="dp-c"><li class="alt"><span><span> </span></span></li></ol></div><pre class="javascript" name="code" style="display: none;"></pre><div class="dp-Highlighter bg_javascript"><div class="bar"><div class="tools"><b>[javascript]</b> <a href="#" class="ViewSource" title="view plain" onclick="dp.sh.Toolbar.Command('ViewSource',this);return false;">?</a><div style="position: absolute; left: 0px; top: 0px; width: 0px; height: 0px; z-index: 99;"><embed id="ZeroClipboardMovie_8" src="http://static.blog.csdn.net/scripts/ZeroClipboard/ZeroClipboard.swf" loop="false" menu="false" quality="best" bgcolor="#ffffff" width="0" height="0" name="ZeroClipboardMovie_8" align="middle" allowscriptaccess="always" allowfullscreen="false" type="application/x-shockwave-flash" pluginspage="http://www.macromedia.com/go/getflashplayer" flashvars="id=8&width=0&height=0" wmode="transparent"></div></div></div><ol start="1" class="dp-c"><li class="alt"><span><span> </span></span></li></ol></div><pre class="javascript" name="code" style="display: none;"></pre> <p><br> </p> <div class="UBBContent">PopUpManager.removePopUp(this);可以移除当前弹出窗口;注意:弹出窗口的关闭按钮在默认状态时是不能关闭当前窗口的,需要使用下面两种方法:<br> </div> <div class="UBBContent"><mx:TitleWindow xmlns:mx="<a target="_blank">http://www.adobe.com/2006/mxml</a>" layout="absolute" showCloseButton="true"<span style="color:red"><strong>close="{PopUpManager.removePopUp(this)}</strong></span>"></div> <div class="UBBContent">或者:</div> <div class="UBBContent"><br> <mx:TitleWindow xmlns:mx="<a target="_blank">http://www.adobe.com/2006/mxml</a>" creationComplete="addEventListener(<span style="color:red"><strong>CloseEvent.CLOSE</strong></span>,closeWindow);" showCloseButton="true"><br> < mx:Script><br> < ![CDATA[<br> import mx.managers.PopUpManager;<br> import mx.events.CloseEvent;<br> <br> private function closeWindow(ev:CloseEvent):void {<br> PopUpManager.removePopUp(this);<br> }<br> ]]><br> < /mx:Script><br> < /mx:TitleWindow><br> </div> <p> </p>public var firstwindow:Firstwindow = new Firstwindow(); public var linetwindow:LineRender = new LineRender(); //使用组件对象打开弹出式窗口的最大好处是可以重用组件并保持所以的状态值. private function createWindow(e:MouseEvent):void { firstwindow.addEventListener("pop",getwindowData); PopUpManager.addPopUp(firstwindow,this,false); PopUpManager.centerPopUp(firstwindow); windowInnerStartDragging(e); }
版权声明:本文内容由互联网用户自发贡献,该文观点与技术仅代表作者本人。本站仅提供信息存储空间服务,不拥有所有权,不承担相关法律责任。如发现本站有涉嫌侵权/违法违规的内容, 请发送邮件至 dio@foxmail.com 举报,一经查实,本站将立刻删除。