views:

19

answers:

1

When the Flex SDK converts MXML to actionscript it generates a lot of databinding code. Sometimes, however, I don't want to bind a variable, for example if I know the variable will not change.

I can't seem to find a work around in Flex to disable the autogenerated databinding.

Also, I was hoping this might also help with some of the runtime warnings thrown by databinding. To get around them, I sometimes use the following, which only throws syntax warnings (and don't appear in my console at runtime). Syntax warning: Data binding will not be able to detect changes when using square bracket operator. For Array, please use ArrayCollection.getItemAt() instead.

+1  A: 

The following tag will tell Flex SDK that variable do not really change and remove "Unable to bind ..." warnings:

[Bindable("__NoChangeEvent__")]
private var model:MyModel = MyModel.instance;

Next, move array[i]-like expressions to a separate function in order to remove warnings. If you had this:

<mx:Button label="{array[i]}"/>

Then create a function:

private function buttonLabel(i):String
{
    return array[i];
}

And the MXML:

<mx:Button label="{buttonLabel(i)}"/>

P.S: If button label changes in runtime then you can add [Bindable(...)] metatags to the function:

[Bindable("stringsChange")]
private function buttonLabel(i):String
{
    return array[i];
}

dispatchEvent(new Event("stringsChange"));
Maxim Kachurovskiy