Flex之TitleWindow学习

来源:互联网 发布:截图软件snagit 编辑:程序博客网 时间:2024/04/27 05:21

转帖:http://www.gold98.net/blog/article.asp?id=878

官方参考:

http://livedocs.adobe.com/flex/2/langref/mx/containers/TitleWindow.html

http://livedocs.adobe.com/flex/3/html/help.html?content=layouts_12.html

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. 
 


主测试文件:

 程序代码


<?xml version="1.0" encoding="utf-8"?>
<mx:Application xmlns:mx="http://www.adobe.com/2006/mxml" layout="absolute">
    <mx:Style>
        Panel{
            fontSize:12px
        }
        Button{
            fontSize:12px
        }
    
    </mx:Style>
    <mx:Script>
        <![CDATA[
        import mx.managers.PopUpManager;
        import mx.containers.TitleWindow;
                                import flash.geom.Point;
        
                                private var point1:Point = new Point();
        private function openWin():void
        {
        var login:Win2=Win2(PopUpManager.createPopUp( this, Win2 , true));            
        point1.x=(p1.width-login.width)/2;
                                point1.y=(p1.height-login.height)/2;          
                                login.x=point1.x+35;
                                login.y=point1.y+35;
                                login.loginUserName=returnValue;
        }
        ]]>
    </mx:Script>
    <mx:Panel id="p1" x="97" y="65" width="800" height="600" layout="absolute" title="弹出窗口测试">
        <mx:Button id="myButton" x="257" y="302" label="Login" click="openWin()"/>
        <mx:Text id="returnValue" text="" />       
    </mx:Panel>
    
</mx:Application>



我们通过(p1.width-login.width)/2和(p1.height-login.height)/2实现弹出窗口的居中!

PopUpManager.createPopUp( this, Win2 , true) 参数:父显示对象,要显示的对象,是否为模态窗口;


Win2.mxml

 程序代码

<?xml version="1.0" encoding="utf-8"?>
<mx:TitleWindow xmlns:mx="http://www.adobe.com/2006/mxml" layout="absolute" width="500" height="400" showCloseButton="true">
    <mx:Script>
        <![CDATA[
     import mx.managers.PopUpManager;
     import mx.containers.TitleWindow;
             import flash.geom.Point;
             import mx.controls.Text;
        
             private var point1:Point = new Point();
             public var loginUserName:Text;
             public var loginUserPwd:Text;
             private function closeWin():void
             {
                 PopUpManager.removePopUp(this);
             }
             
             private function openNewWin():void
             {
            var login:Win1=Win1(PopUpManager.createPopUp( this, Win1 , true)); 
            point1.x=(this.width-login.width)/2;
            point1.y=(this.height-login.height)/2;          
            login.x=point1.x+5;
            login.y=point1.y+5;
      
             }
             
             private function loginOk():void
             {
                 loginUserName.text=username.text;
                 PopUpManager.removePopUp(this);
             }
        ]]>
    </mx:Script>
    <mx:Style>
        Label{fontSize:12px;}
    </mx:Style>
    <mx:Button x="139" y="258" label="open new" click="openNewWin()"/>
    <mx:Button x="282" y="258" label="close" click="closeWin()"/>
        <mx:Label x="139" y="87" text="用户名:"/>
        <mx:Label x="139" y="134" text="密  码:"/>
        <mx:TextInput x="200" y="87" id="username"/>
        <mx:TextInput x="200" y="134" id="userpwd" displayAsPassword="true"/>
        <mx:Button x="227" y="258" label="ok" click="loginOk()"/>
</mx:TitleWindow>



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>




loginUserName.text=username.text;与上章中的login.loginUserName=returnValue;实现了弹窗之间到主程序间的信息传递,当用户输入用户名点击OK按钮时,弹窗关闭,而输入的用户名返回主程序窗口并显示!(显示在returnValue的Text标签里)

关于关闭按钮的自定义皮肤问题:

 程序代码

TitleWindow
{
    closeButtonDisabledSkin: Embed("panel/up.png");
    closeButtonDownSkin: Embed("panel/up.png");
    closeButtonOverSkin: Embed("panel/over.png");
    closeButtonUpSkin: Embed("panel/up.png");    
}
原创粉丝点击