Accessing a Flex component for another component
I have 2 components, for example (editor.mxml using mx: windows), when I click the edit button, I want to get the current value from the data field of another component? (datagrid.mxml using mx window :)
I know how to access the main MXML data file using the parentDocument or Application.application method, but is blocked if I want to access a different path as above. Keep the code as simple as possible.
You can either do dependency injection , that is, provide the component with a A
reference to the component B
so that they can communicate (example of a tighter coupling), or both components communicate through a common mediator using events (an example of looser coupling).
Both of these options will be implemented wherever you create these components ( A
and B
in this example) and add them to the display list.
source to share
This might be more complicated than it deserves and it spoils the boilerplate fever, but you can use a mediator class that listens for the CLICK event from the button and knows enough about the other component to request its property. It can even transmit this data using a custom event that the button listens to.
While this involves three classes instead of two, it often turns out to be easier to have two components that focus on looking good and one that worries about coordination.
Greetings
source to share