views:

882

answers:

2

I've developed a component which is a combination of a few items (canvas, labels, etc...) but when I try to bind it to a variable such as : {stationXML.getItemAt(1).AAA.@value}, it doesnt work. Before I combined all the items in a component, they were all in the main MXML file at which time they worked.

Not sure if it matters, but the "stationXML" arraycollection variable is declared inside the file "Station.as".

Any ideas?

A: 

does Station.as extend EventDispatcher and does the class (or property) carry the [Bindable] metadata tag? For binding to work your class needs to extend EventDispatcher someplace in its inheritance structure so that it is able to notify binding "clients" that it has updated.

Joel Hooks
Station.as does not extend the EventDispatcher. How do I do this, and what does it do? The item is declared as bindable such as:[Bindable]public var stationXML:ArrayCollection = new ArrayCollection;
Seidleroni
+1  A: 

When you say "global variable" where and how exactly is it declared? There aren't really such a thing as a global variable in a Flex application. If you declare something in your main MXML class that doesn't make it global, it makes it accessible by the instance of that main application class. If you want to access that value within a component then you must pass it down to that component. Alternatively, you could implement a singleton class to effectively provide "global" access to those values.


eg, in the component, create a public property:

public var xmlData:XML;

then in the main mxml, pass the value down:

<xxx:MyComponent id="foo" x="10" xmlData="{theValue}"/>
Marplesoft
I'm sorry for my incorrect statement. The item is declared as a "public" variable (bindable) in the Station.as file. How do I pass that value down to that component?
Seidleroni
You would define a public property on the component that outside things can "set". Then just set that property from the main mxml. See my edit above.
Marplesoft
Thank you very much, this worked perfectly! The only change was that I had to make the variable (xmlData) bindable inside the component. One question, however. Will the application create an entirely new XML variable inside the component (doubling the memory taken up by essentially the same item) or is it more like a pointer?
Seidleroni
It will just point to the existing variable.
Marplesoft