flex 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;

全部代码如下:
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>
  • 0
    点赞
  • 1
    收藏
    觉得还不错? 一键收藏
  • 0
    评论

“相关推荐”对你有帮助么?

  • 非常没帮助
  • 没帮助
  • 一般
  • 有帮助
  • 非常有帮助
提交
评论
添加红包

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

当前余额3.43前往充值 >
需支付:10.00
成就一亿技术人!
领取后你会自动成为博主和红包主的粉丝 规则
hope_wisdom
发出的红包
实付
使用余额支付
点击重新获取
扫码支付
钱包余额 0

抵扣说明:

1.余额是钱包充值的虚拟货币,按照1:1的比例进行支付金额的抵扣。
2.余额无法直接购买下载,可以购买VIP、付费专栏及课程。

余额充值