您的位置:首页 > 职场人生

flex TitleWindow之间数据传输的示例

2011-10-09 17:04 459 查看
在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>
内容来自用户分享和网络整理,不保证内容的准确性,如有侵权内容,可联系管理员处理 点击这里给我发消息
标签:  实例 职场 休闲