tags:

views:

638

answers:

2

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.

+1  A: 

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.

hasseg
A: 

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

Richard Haven