开发者

Bind a Boolean variable inside an ArrayCollection

[Bindable]
public var isToggled:Boolean = true;

public var menuData:Array = [
    {label: "Sample", type: "check", toggled: {开发者_开发技巧isToggled}}
];

I'm trying to bind the isToggled variable to the toggled property but I'm getting this error: 1084: Syntax error: expecting colon before dot. Maybe because it is treating {isToggled} as another object. Is there a workaround for this?


You can't have advantages of declarative data binding within ActionScript code. It is allowed only within MXML tags. But you can declare your Array or ArrayCollection with MXML:

<fx:Declarations>
    <s:ArrayCollection id="myCollection">
        <s:source>
            <fx:Array>
                <fx:Object label="Sample" type="check" toggled="{isToggled}" />
            </fx:Array>
        </s:source>
    </s:ArrayCollection>
</fx:Declarations>


You can't use bindings ('{}') outside of mxml unless you use BindingUtils. However, I wouldn't recommend that either because now you're copying your data.

Why do you need 2 boolean values? You already have the data just bind it using the menuData property.

0

上一篇:

下一篇:

精彩评论

暂无评论...
验证码 换一张
取 消

最新问答

问答排行榜