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: What is considered the best practice for adding viewComponents to the stage?  (Read 9512 times)
inchworm
Jr. Member
**
Posts: 13


View Profile Email
« on: January 30, 2010, 12:10:50 »

First of all, thank you Cliff for all of your hard work on the framework and also your dedication to this forum. It's really great, as a self taught developer, to have places like this to go to which are active and responsive and help me along my way.

I have a rather simple application right now which displays a 3D timeline. The timeline has very little functionality and as such only needs one mediator. My current setup is an ApplicationMediator with a reference to the stage as its viewComponent, and a TimelineMediator with an instance of the 3D timeline as its viewComponent.

When I want to add the timeline to the stage/display list, I can think of two ways to do it. One way would be to send a notification with a reference to the timeline viewComponent as its body. Then the ApplicationMediator would handle that note and add it to stage. The other way is to have the ApplicatationMediator listen for a notification and then add the viewComponent through its mediator's reference in the facade.
:
addChild(facade.retrieveMediator(TimelineMediator.NAME).getViewComponent() as DisplayObject);
I've used both methods and they work well but I was wondering if there is an alternative best practice that maybe I don't know about? Is it ever wise to pass a stage reference to your Mediators and just forgo the ApplicationMediator/StageMediator all together?

Thanks!

- Rob
Logged
mariusht
Full Member
***
Posts: 26


View Profile Email
« Reply #1 on: January 30, 2010, 02:17:33 »

Go with:
...send a notification with a reference to the timeline viewComponent as its body. Then the ApplicationMediator would handle that note and add it to stage.

You don't want to make dependencies between mediators in you application.

Mariush T.
http://mariusht.com/blog/
Logged
inchworm
Jr. Member
**
Posts: 13


View Profile Email
« Reply #2 on: January 31, 2010, 01:21:43 »

thanks mariush!
Logged
puremvc
Global Moderator
Hero Member
*****
Posts: 2871



View Profile WWW Email
« Reply #3 on: January 31, 2010, 08:33:46 »

...send a notification with a reference to the timeline viewComponent as its body. Then the ApplicationMediator would handle that note and add it to stage.
This is the right approach. Don't pass around references to the stage, and try not to retrieve and manipulate mediators if you can avoid it.

-=Cliff>
« Last Edit: February 01, 2010, 08:26:30 by puremvc » Logged
inchworm
Jr. Member
**
Posts: 13


View Profile Email
« Reply #4 on: February 01, 2010, 02:39:23 »

Is it ok to retrieve mediators in my commands? Or should i be going about that differently as well?
Logged
mariusht
Full Member
***
Posts: 26


View Profile Email
« Reply #5 on: February 01, 2010, 07:42:45 »

Command may register, retrieve and remove another Proxy or Mediator

Look at my blog post http://mariusht.com/blog/2009/05/28/puremvc-actors-and-their-responsibilities/

Mariush T.
http://mariusht.com/blog/
Logged
puremvc
Global Moderator
Hero Member
*****
Posts: 2871



View Profile WWW Email
« Reply #6 on: February 01, 2010, 08:28:19 »

Is it ok to retrieve mediators in my commands? Or should i be going about that differently as well?

The best practices document does mention that this is a practice to be avoided. Communicate with Mediators by sending them notifications if possible.

-=Cliff>
Logged
Pages: [1]
Print