views:

40

answers:

1

Hi there!

I read (twice) this very useful article: http://blogs.adobe.com/flexdoc/pdfs/modular.pdf

And, I know that the best way to make a connection from my main app to my modules is through interfaces.

So, my problem is, how can I implement an interface so my module can send and receive data from my main app?, cuz, I understand that my module implements an interface that is used by my main app.. but, can I do it "viceversa"?

Other issue I have is, why do I need to call my main app children if I can just import a module's class?... I think this is cuz the need of keep the modularity, but Im not sure.

Thx in advance!

+1  A: 

You could pass in a 'bridge' interface into your 'modules' when the MainApp has created them. This object would allow the module to call functions to send data.

So, for example, if the module interface was

function get name() : String 
function get version() : String
function performAction() : void // Blah blah

You could extend it to also include

function set mainAppBridge(bridge:MainAppBridge) : void

The MainAppBridge interface could have a method such as:

function receiveResult(data:Object) : void

After the MainApp instanciates a 'module' it will then call the set mainAppBridge passing in an implementation of a MainAppBridge. The 'module' is then free to call the methods available on that bridge.

As all this is done with interfaces, you can implement the actual functionality how-ever you like.

Richie_W
I'll give it a try, thx for your answer.
Artemix