Sharing variables between mxml components

Kamo picture Kamo · May 29, 2010 · Viewed 8k times · Source

I have several mxml components in an app, all of which need the same variable called genericX. I've included that variable in the main mxml and made it public

[Bindable] public var genericX:Number = 102;

but I still can't access it from other mxml components. If I try to do this for example, it doesn't recognize the variable.

<s:Button x="{genericX}" label="Click" />

Answer

Simon Gladman picture Simon Gladman · Jun 1, 2010

There's also a filthy solution that works but isn't nice. You can create a static variable against the application class. For example:

[Bindable] public static var genericX : Object

You can access that from anywhere like this:

MyApplicationName.genericX

It ain't pretty, but it does work :)

simon