0
votes

I have 2 components for example (editor.mxml using mx:windows), when I click an edit button, I want to get the current value from the other component's datafield? (datagrid.mxml using mx:window)

I do know how to access the main MXML's datagrid by parentDocument or Application.application method, but stumped block if I want to access other way as mentioned above. Keep the code as simple as possible.

4
Are both components launched from the parent application?defmeta

4 Answers

1
votes

You could either do dependency injection, that is, give component A a reference to component B so that they can communicate directly (example of tighter coupling,) or have both components communicate through a common mediator using events (example of more loose coupling.)

Both of those options would be implemented wherever it is that you're creating those components (A and B in this example) and adding them to the display list.

0
votes

This might be more complicated than it deserves, and it smacks of Pattern-Fever, but you could use a mediator class that listens for the CLICK event from the button and knows enough about the other component to query its property. It could even transmit that data using a custom event, which the button listens for.

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.

Cheers

0
votes

Try this:

FlexGlobals.topLevelApplication

This points Your root. From the root You can grab every element You want.

0
votes

You can also add an id to the custom component like this,

<custom:Editor id="myCustomComponent">

  </Editor:AddressForm>

and

access your datagrid's value like this,

var data:ArrayCollection = myCustomComponent.DatagridID.dataProvider;