Actionscript – Sharing variables between mxml components

actionscriptadobeapache-flexflex4mxml

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" />

Best Answer

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

Related Topic