Futurescale, Inc. PureMVC Home

The PureMVC Framework Code at the Speed of Thought


Over 10 years of community discussion and knowledge are maintained here as a read-only archive.

New discussions should be taken up in issues on the appropriate projects at https://github.com/PureMVC

Pages: [1]
Print
Author Topic: Communicating between widgets  (Read 11395 times)
memorycraft
Newbie
*
Posts: 2


View Profile WWW Email
« on: May 01, 2008, 10:14:44 »

Hi

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?

regards
« Last Edit: May 01, 2008, 10:16:51 by memorycraft » Logged
zilet
Courseware Beta
Jr. Member
***
Posts: 17


View Profile WWW Email
« Reply #1 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 :
:
Facade.getInstance(masterName);

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.
Logged
punchjunkie
Newbie
*
Posts: 9


View Profile Email
« Reply #2 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!

Thanks!

-Tony
Logged
puremvc
Global Moderator
Hero Member
*****
Posts: 2871



View Profile WWW Email
« Reply #3 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.

-=Cliff>
Logged
memorycraft
Newbie
*
Posts: 2


View Profile WWW Email
« Reply #4 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?

 
Logged
zilet
Courseware Beta
Jr. Member
***
Posts: 17


View Profile WWW Email
« Reply #5 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.
Logged
puremvc
Global Moderator
Hero Member
*****
Posts: 2871



View Profile WWW Email
« Reply #6 on: May 04, 2008, 06:52:25 »

Memorycraft,

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.

-=Cliff>
Logged
Pages: [1]
Print