在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>
更多文章、技術(shù)交流、商務(wù)合作、聯(lián)系博主
微信掃碼或搜索:z360901061

微信掃一掃加我為好友
QQ號聯(lián)系: 360901061
您的支持是博主寫作最大的動(dòng)力,如果您喜歡我的文章,感覺我的文章對您有幫助,請用微信掃描下面二維碼支持博主2元、5元、10元、20元等您想捐的金額吧,狠狠點(diǎn)擊下面給點(diǎn)支持吧,站長非常感激您!手機(jī)微信長按不能支付解決辦法:請將微信支付二維碼保存到相冊,切換到微信,然后點(diǎn)擊微信右上角掃一掃功能,選擇支付二維碼完成支付。
【本文對您有幫助就好】元
