Question

I have been using { } around variables in MXML without really understanding what they are for. I am now needing to know if I should use it around a variable..what does that do?

example: <mx:label text="{variable}"/>

Was it helpful?

Solution

That's a binding!,
In this case, it means that the text of the label will show the content of "variable", if you change the value of "variable" it will also change the text displayed by the label.

OTHER TIPS

As stated above, this is will bind a variable to that object.

<mx:label text="{variable}"/>

This will bind variable to the label, so that whenever variable is changed, the text in the label will also change. One other thing to keep in mind would be that you have to set the variable to be Bindable like so:

<mx:Script>
    ...
    [Bindable]
    private variable:String = "Label";
    ...
</mx:Script>

The {braces} formation lets you set a control to respond when a label changes. Any variable that is marked with a [Bindable] attribute like this:

[Bindable]
public var s:String;

can be placed in binding statement.

Keep in mind that if you want to bind to an array that you should use an ArrayCollection rather than a standard Array, because ArrayCollection implements IList and ICollectionView, which allows it to fire updates to the control whenever an item is added or removed from the collection, and arrays require the control to be manually updated to keep in sync.

As stated several times already, that is indeed a data binding. There is a nice little article from adobe on using data bindings in flex.

Licensed under: CC-BY-SA with attribution
Not affiliated with StackOverflow
scroll top