PureMVC Architects Lounge

PureMVC Manifold => MultiCore Version => Topic started by: memorycraft on May 01, 2008, 10:14:44

Title: Communicating between widgets
Post by: memorycraft on May 01, 2008, 10:14:44

i 'm just making a widget application using AS3 MultiCore version
and was encounterd some problems for same reason.

it's just about communicating between widgets.
in one core, i can notify to other classes with sendNotification();
but i can't have any good idea about communicating between each widgets.

in Modularity Demo, platform and widgets communicate via IWidgetShell interface.
but in real application, we need more opportunities to liaise between widgets.
so i would like to use some notification architecture over widget cores.

is there any good practice?


Title: Re: Communicating between widgets
Post by: zilet on May 02, 2008, 06:20:51
I only had requirements to comunicate with 'master' application.
Master application loads a lot of modules and each of the modules has its own facade. Some modules had to interact with 'master' application so the solution was to retrieve 'master' facade by :

masterName is constant. And then send the notification to that app. This is a bit of chaining but it is an easy way to solve the problem.

Title: Re: Communicating between widgets
Post by: punchjunkie on May 02, 2008, 02:18:18
Hi Zilet,

I tried passing a key (from the master app) into module to sent a notification but I receive a 'null' of the facade instance. I tried to debug it referring to another forum post for debugging, but apparently my version of Flex 3 doesn't have the option to view "inaccessible member vars".. at least to m knowledge.

Do you have a basic sample from a child app calling the parent app; would be greatly appreciated!



Title: Re: Communicating between widgets
Post by: puremvc on May 03, 2008, 07:59:08
It is not a good practice to share a facade instance around outside its core.

The big problem is notification namespace management. Guaranteeing that noticication strings are unique across cores requires a scheme.

One way to communicate across module boundaries is with events. Modules are view components, give them mediators in the shell app and let them communicate with the system like other view components.


Title: Re: Communicating between widgets
Post by: memorycraft on May 03, 2008, 10:43:34
Hi, zilet

if there is no support for communicating between widgets and master.
i just suggest that you should add some interface methods to widget shell and widgets(or buttons that invoke widget).

in each interfaces, define like below.
public function sendApplicationNotificaction(key:String, noteBody:Object):void;
in each implements(ex:hoge.mxml),
public  sendApplicationNotificaction(key:String, noteBody:Object):void{
  dispatchEvent(new CustomNoticeEvent(CustomNoticeEvent.NOTICE, key, noteBody);

in each Mediator subclasses
hoge.addEventListener(CustomNoticeEvent.NOTICE, onApplicationNotice);
private function onApplicationNotice(event:CustomNoticeEvent):void{
  sendNotification(event.key, event.noteBody);

How about this?


Title: Re: Communicating between widgets
Post by: zilet on May 03, 2008, 11:32:16
@memorycraft: As I understood you are just suggesting a bit more abstraction. But then again when you want to send a notification to some other facade instance it is required to get that instance. So the approach will be the same.

@cliff: Yes well events are a good solution but I was used to notifications for inter modular communication, but you are right. It is cleaner.

Title: Re: Communicating between widgets
Post by: puremvc on May 04, 2008, 06:52:25

Sorry, I mistook you on the use of a single  command.

Certainly if you move the switch to a single command it would be equivalent to using a mediator as described. The registration would be bulkier code than listNotification, but the command is actually where it should go.