2011-08-12 146 views
0

我有一個關於如何從彈出窗口訪問主窗口變量的問題。在彈出窗口中重新加載主窗口的變量

創建在主窗口中的彈出窗口,並通過可變「內容」到這個彈出窗口爲以下代碼:

<mx:Script> 
    <![CDATA[ 
    // ...... 
    popwin = PopUpManager.createPopUp(UIComponent(parentApplication), PopupWindow, true) as PopupWindow; 
    popwin.parentView = this; // parentView is an IFlexDisplayObject 
    popwin.content = content; 
    PopUpManager.centerPopUp(popwin); 
    // ...... 
    ]]> 
</mx:Script> 

在popwin,我改變的「內容」的變量的值,但我當點擊popwin上的「重置」按鈕時,要重置「內容」的值。

我知道,我派遣在popwin窗口的事件,並在主窗口 代碼片段popwin添加監聽器:

parentView.dispatchEvent(new CustomEvent(CustomEvent.RESET)); 

代碼片段在主窗口:

addEventListener(CustomEvent.RESET, resetContent); 

public function resetContent():void{ 
    this.content = loadContent(); 
} 

但價值「內容」在popwin中不重置。

有什麼我錯過了嗎?

是否有任何其他方法來更新彈出窗口中的「內容」?

=====================問題更新於15/8/2011 ================= =============

我用下面的popwin的createComplete代碼()函數:

BindingUtils.bindProperty(textInput, "text", content, "name", false); 

當我改變TextInput文本的價值和重置內容,將其加載我的跟蹤日誌中的content.name的原始值,但textInput的文本值不會恢復爲原始值。

如果我使用下面的代碼,而不是BindingUtils.bindProperty:

[Bindable] 
public var content:Content; 
...... 
<mx:TextInput id="textInput" text="{content.name}" /> 

,做同樣的動作,content.name被重新加載在我的跟蹤日誌,但文本值設置爲空白,爲textInput。

有人知道爲什麼嗎?

回答

0

嘗試使用:再次

popwin = PopUpManager.createPopUp(UIComponent(parentApplication), PopupWindow, true) as PopupWindow; 
popwin.parentView = this; // parentView is an IFlexDisplayObject 
popwin.content = content; 
BindingUtils. bindProperty(popwin, "content", this, "content", false, true); 
PopUpManager.centerPopUp(popwin); 
+0

我以爲bindProperty可以工作,但它不適合我。 「內容」是popwin中的一個對象,它將是中繼器組件的dataProvider。當我更改該轉發器組件的文本值並嘗試重置它時,它不會加載原始值。 – Wei

+0

我試圖找到重置時數據提供程序不更新的位置和原因。也許是由於其他原因。但如果有人有一些建議,請在這裏發表您的評論。非常感謝你。 – Wei

+0

在'this.content = loadContent()'這一行中,您將this.content的指針更改爲另一個內存區域,但彈出窗口的content屬性的指針仍然指向前一個區域。數據綁定在ActionScript中不起作用。您可以使用'BindingUtils'調用綁定,我無法理解爲什麼這個解決方案不適合您的體系結構,而綁定完全適合您的需求? – Constantiner

0

只需設置內容。

public function resetContent():void{ 
    if (popwin != null){ 
    popwin.content = this; 
    } 
}