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时(通常都是这样)。 –