Flex之TitleWindow

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>  
loginUserName.text=username.text;
由于loginUserName是父窗口传过来的组件,所以此句赋值就是把子窗口的返回值传到父窗口。



PopUpManager.removePopUp(this);可以移除当前弹出窗口;注意:弹出窗口的关闭按钮在默认状态时是不能关闭当前窗口的,需要使用下面两种方法:
<mx:TitleWindow xmlns:mx=" http://www.adobe.com/2006/mxml" layout="absolute" showCloseButton="true" close="{PopUpManager.removePopUp(this)}">
或者:

<mx:TitleWindow xmlns:mx=" http://www.adobe.com/2006/mxml" creationComplete="addEventListener( CloseEvent.CLOSE,closeWindow);" showCloseButton="true"> < mx:Script> < ![CDATA[ import mx.managers.PopUpManager; import mx.events.CloseEvent; private function closeWindow(ev:CloseEvent):void { PopUpManager.removePopUp(this); } ]]> < /mx:Script> < /mx:TitleWindow>

相关文章

一:display:flex布局display:flex是一种布局方式。它即可以...
1. flex设置元素垂直居中对齐在之前的一篇文章中记载过如何...
移动端开发知识点pc端软件和移动端apppc端软件是什么,有哪些...
最近挺忙的,准备考试,还有其他的事,没时间研究东西,快周...
display:flex;把容器设置为弹性盒模型(设置为弹性盒模型之后...
我在网页上运行了一个Flex应用程序,我想使用Command←组合键...