0

我正在使用带有 Halo 主题的 Flex 4.0,以及我拥有的自定义组件。我想用参数调用组件来隐藏或显示一些项目。该参数是动态的,这意味着它是在加载 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变量。所以当被调用时,按钮被绘制。trueallowClosecreateChildren()

我怎样才能改变行为?如果需要的话,我不介意按钮是否先被绘制,然后再被删除,但我不知道如何进行参数值的这种绑定。

例如,当我将title属性更改为 时{allowClose},会显示布尔值false,即使true最初可能传递了 a 。

4

1 回答 1

1

注意:已编辑以反映反馈

由于您使用的是 Flex 4,因此您可能应该使用皮肤和皮肤内的状态来执行此操作。但是,如果您想通过代码来实现,请尝试以下操作:

protected var _allowClose:Boolean=true;
protected var _allowCloseChanged::Boolean=true;
protected var _closeButton:Sprite = new Sprite();


public function get allowClose():Boolean {
    return _allowClose;
}

public function set allowClose(value:Boolean):void {
    if (value != _allowClose) {
       _allowClose=value;
       _allowCloseChanged=true;
       invalidateProperties();
    }
}

override protected function commitProperties():void {
   if (_allowCloseChanged) {
       if (_allowClosed) {
            titlebar.addChild(_closeButton);
            drawCloseButton(true);
       } else {
            titleBar.removeChild(_closeButton);
       }
       //you need to set this back false...sorry I left that out
       _allowCloseChanged=false;
   }
   super.commitProperties();
}

注意:在这种情况下,您不再需要覆盖 createChildren

于 2011-09-29T13:01:18.440 回答