在Flex里,一般的彈出窗口(除了Alert以外)都可以用TitleWindow組件完成,主窗口和TitleWindow的數(shù)據(jù)傳輸可以用以下方法:
假設(shè)TitleWindow的實(shí)例文件為titleWin.mxml,則要在Application中用PopUpManager創(chuàng)建一個(gè)titleWin的引用
private var popWin:titleWin = titleWin(PopUpManager.createPopUp(this,titleWin,true));
如果要將Application的一個(gè)組件的值傳給titleWin,如Application的id="userName"的TextInput的值傳給titleWin,必須先在titleWin.mxml里聲明一個(gè)TextInput的組件:
public var userNameInPop:TextInput;
然后在Application里:
popWin.userNameInPop=userName;
這樣就相當(dāng)于把Application的userName的TextInput組件傳給了titleWin,可以在titleWin.mxml里綁定這個(gè)值然后在文本框里顯示出來:
[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>