Exchange variables between mxml components

I have several mxml components in an application that require the same variable called genericX. I included this variable in the main mxml and made it publicly available.

[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 does not recognize the variable.

<s:Button x="{genericX}" label="Click" />
+3
source share
5 answers

There's also a dirty solution that works, but not nice. You can create a static variable against the application class. For instance:

[Bindable] public static var genericX : Object

You can access this from anywhere:

MyApplicationName.genericX

It is not very, but it works :)

simon

+4

. Flex -, Events, MXML , eventDispatcher.

[Bindable] public var genericX: Number = 102;

private function init():void {

var evt:NewCustomEvent = new CustomEvent(CustomEvent.SENDDATA);
evt.genericaValue = genericX
dispatchEvent(evt);

}

MXML, , addEventListner(), .

, , .

+3

:

Flex 3:

var app:Application = mx.core.Application.application as Application;

Flex 4 (, ):

var app:Object = FlexGlobals.topLevelApplication;

:

<s:Button x="{app.genericX}" label="Click" />
+1

MXML, .

0
x="{parentApplication.genericX}"
0

Source: https://habr.com/ru/post/1747643/


All Articles