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.

0


source to share


4 answers


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.

+1


source


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

0


source


Try the following:

FlexGlobals.topLevelApplication

      

This points to your root. From the root, you can grab every element you want.

0


source


You can also add an id to the custom component, for example

<custom:Editor id="myCustomComponent">

  </Editor:AddressForm>

      

and

access your datagrid value for example

var data:ArrayCollection = myCustomComponent.DatagridID.dataProvider;

      

0


source







All Articles