• 2010年8月26日_TitleWindow_Flex控件


    /*********************************************************************/

    //flex TitleWindow之间数据传输的示例

    //2010年8月26日

    //转载来源:http://aaagu1234.blog.163.com/blog/static/4009371520096865727641/

    /*********************************************************************/

    TitleWindow就是弹出一个类似于alert效果的窗口,

    //下面是一个简单的弹出的titleWindow组件

     

    在Flex里,一般的弹出窗口(除了Alert以外)都可以用TitleWindow组件完成,主窗口和TitleWindow的数据传输可以用以下方法:

    假设TitleWindow的实例文件为titleWin.mxml,则要在Application中用PopUpManager创建一个titleWin的引用

    private var popWin:titleWin = titleWin(PopUpManager.createPopUp(this,titleWin,true));

    如果要将Application的一个组件的值传给titleWin,如Application的id="userName"的TextInput的值传给titleWin,必须先在titleWin.mxml里声明一个TextInput的组件:

    public var userNameInPop:TextInput;

    然后在Application里:

    popWin.userNameInPop=userName;

    这样就相当于把Application的userName的TextInput组件传给了titleWin,可以在titleWin.mxml里绑定这个值然后在文本框里显示出来:

    [Bindable]

    public var userNameInPop:TextInput;

    <mx:TextInput x="110" y="39" id="popUserName" text="{userNameInPop.text}"/>

    而要把titleWin的值传给Application则只需在titleWin.mxml里把TextInput的值赋给userNameInPop的text即可:

    userNameInPop.text=popUserName.text;

    全部代码如下:

    Actionscript代码

    titleWin.mxml 

    <?xml version="1.0" encoding="utf-8"?> 

    <mx:TitleWindow xmlns:mx="http://www.adobe.com/2006/mxml" layout="absolute" width="400" height="300" showCloseButton="true" close="PopUpManager.removePopUp(this)"> 

        <mx:Script> 

            <![CDATA[ 

                import mx.managers.PopUpManager; 

                //[Bindable] 

                //public var userName:TextInput; 

                [Bindable] 

                public var userNameInPop:TextInput; 

                [Bindable] 

                public var userEmailInPop:TextInput; 

                private function showText():void 

                { 

                    userNameInPop.text=popUserName.text; 

                    userEmailInPop.text=popEmail.text; 

                    PopUpManager.removePopUp(this); 

                } 

            ]]> 

        </mx:Script> 

        <mx:Label text="用户名:" x="57" y="41"/><mx:TextInput x="110" y="39" id="popUserName" text="{userNameInPop.text}"/> 

        <mx:Label text="邮箱:" x="57" y="71"/><mx:TextInput x="110" y="69" id="popEmail" text="{userEmailInPop.text}"/> 

        <mx:Button x="157" y="99" label="Button" click="showText()"/> 

        

    </mx:TitleWindow> 

     

    mainWindow.mxml 

    <?xml version="1.0" encoding="utf-8"?> 

    <mx:Application xmlns:mx="http://www.adobe.com/2006/mxml" layout="absolute"> 

        <mx:Script> 

            <![CDATA[ 

                import mx.managers.PopUpManager; 

                private function pop():void 

                { 

                    var popWin:titleWin = titleWin(PopUpManager.createPopUp(this,titleWin,true)); 

                    popWin.title="弹出窗口"; 

                    popWin.userNameInPop=userName; 

                    popWin.userEmailInPop=email; 

                } 

            ]]> 

        </mx:Script> 

        <mx:Label text="用户名:" x="106" y="95"/><mx:TextInput x="159" y="91" id="userName" text="ssz413"/> 

        <mx:Label text="邮箱:" x="106" y="144"/><mx:TextInput x="159" y="142" id="email" text="ssz425"/> 

        <mx:Button x="207" y="189" label="Button" click="pop()"/> 

        

    </mx:Application>

    运行后显示的效果

    单击按钮后的效果

     

  • 相关阅读:
    [leetcode ]429. N-ary Tree Level Order Traversale (easy)
    [leetcode] 559. Maximum Depth of N-ary Tree (easy)
    [leetcode] 406. Queue Reconstruction by Height (medium)
    [leetcode] 238. Product of Array Except Self (medium)
    [leetcode] 94. Binary Tree Inorder Traversal
    [leetcode] 621. Task Scheduler(medium)
    [leetcode] 309. Best Time to Buy and Sell Stock with Cooldown(medium)
    为窗口设置图标
    关闭住主窗口
    窗口居中显示
  • 原文地址:https://www.cnblogs.com/xingchen/p/1809166.html
Copyright © 2020-2023  润新知