0
我正在使用Flex 4.0,Halo主題和我有源代碼的自定義組件。我想用參數調用組件來隱藏或顯示一些項目。該參數是動態的,意味着它是在mxml加載後的方法中設置的。如何在Flex中動態更新mxml屬性?
段:
<mx:Application xmlns:mx="http://www.adobe.com/2006/mxml"
layout="absolute"
xmlns:ns1="de.aggro.components.*"
width="100%"
height="100%"
initialize="init();"
>
<mx:Script>
<![CDATA[
[Bindable]
public var allowwindowmanipulation:Boolean = true;
internal function init():void {
allowwindowmanipulation = false;
}
]]>
</mx:Script>
<mx:states>
<mx:State name="st">
...
<ns1:CollapsableTitleWindow width="956" height="395" x="294" y="484" id="wnd" title="title" allowClose="{allowwindowmanipulation}">
</mx:State>
</mx:states>
</mx:Application>
CollapsableTitleWindow代碼(片斷):
public class CollapsableTitleWindow extends Panel implements ICTWindow {
public var allowClose:Boolean = true;
function CollapsableTitleWindow(){
super();
addEventListener(FlexEvent.CREATION_COMPLETE, initializeHandler);
}
protected override function createChildren():void{
super.createChildren();
//Create the Buttons
closeButton = new Sprite();
if(allowClose==true){
titleBar.addChild(closeButton);
drawCloseButton(true);
}
}
}
現在,當運行此代碼,給予的CollapsableTitleWindow
構造函數的值是true
爲allowClose
變量。所以當調用createChildren()
時,該按鈕被繪製。
我該如何改變行爲?我不介意如果按鈕第一次被繪製,然後後來被刪除,如果需要的話,但我不知道我怎麼做這個綁定的參數值。
當我爲實例title
屬性更改爲{allowClose}
的false
布爾值被顯示,儘管可能是一個true
在第一個通過。
我調查你的解決方案,因爲我們說話,似乎被正確調用,但我的其他代碼(我沒有包含在代碼片段中)應該發生在「drawCloseButton」代碼附近,目前正在失敗,所以我正在修復第一個.. – Tominator
喜悅,它作品! (我不得不用自己的代碼來調試一下)。但是有兩件事情:commitProperties應該是「protected override」而不是「public」,並且在「if(_allowCloseChanged){」應該是「_allowCloseChanged = false;」謝謝! – Tominator
對不起,早上寫得太早了:)。您必須將其更改爲(!_allowCloseChanged)的原因是因爲我忘記在commitProperties中將其設置爲false。只要_allowClose更改(因此是標誌),您就希望運行該代碼,而不是每次運行commitProperties時(通常都是這樣)。 –