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: Connecting a view component on the stage to a mediator  (Read 9890 times)
shane
Newbie
*
Posts: 1


View Profile Email
« on: March 05, 2009, 09:14:44 »

Is it possible for a view component (movieClip in this case) to instantiate the connection to a mediator?  I'm trying to create an environment where I can drag and drop components for rapid deployment and in order to do this, I need to be able to nest my components and still allow them to communicate.  In the solutions I am deploying I use an arbitrary portion of my components with every build.

Say I have a view component that contains a button.  I would like for this button when pressed to cause another view component to populate it's text box with the text "button pressed" no matter how these movieclips may be nested in other components.  I have almost wrapped my head around the concept of commands and proxies, but I don't know if this kind of connection with a mediator is possible.  Apologies if my question is flawed or unclear, I'm still trying to orient myself to this architecture.

Any advice, comments?
Logged
puremvc
Global Moderator
Hero Member
*****
Posts: 2871



View Profile WWW Email
« Reply #1 on: March 07, 2009, 02:45:39 »

Certainly. Have a Stage or Application mediator that listens for a bubbling event sent by the view component when it is added to the stage. Then have that uber mediator (or a command that it passes the new component to after plucking it from the event) look at the type of component and instantiate the appropriate mediator. Then that mediator spoon feeds the data to the new component.

Have a look at the Slacker deferred instantiation demo for pointers.

-=Cliff>
Logged
flib
Newbie
*
Posts: 4


View Profile Email
« Reply #2 on: March 27, 2009, 05:24:57 »

Ah great idea.

Was struggling with a similar thing.

Thanks!
Logged
Steve
Newbie
*
Posts: 6


View Profile Email
« Reply #3 on: June 13, 2009, 11:43:15 »

Just getting to know pureMVC and already loving it!

This thread seems to tackle the problem I am having - I need to have (in Flex) a 'blank' application file, to which the designers can drag and drop components and have them just work. (The designers have to be kept isolated from any coding). So from the pureMVC point of view, it doesn't know which components may exist on startup - it could be just one, it could be twenty. How would the ApplicationMediator add itself as a listener to the reusable views which should know nothing about the existence of pureMVC? The only way I could see this working would be to wrap all the generic components in a code-behind wrapper which had a reference to the Application Mediator. But this doesn't feel right somehow as the views are then coupled to pureMVC.
Logged
puremvc
Global Moderator
Hero Member
*****
Posts: 2871



View Profile WWW Email
« Reply #4 on: June 14, 2009, 08:00:35 »

@Steve: Just say no to code-behind. There's no avoiding the few lines it sometimes takes for a Mediator to pull some data from a view component and invoke a proxy method or send a note, or to pull data out of a note and poke it into the view component, but ideally that's all any mediator should really be doing.

And the mediators shouldn't have references to each other but instead should communicate by notification. The hierarchy exists in the relationships of actual View Components themselves. PureMVC Mediators simply adapt various nodes of that hierarchy to the MVC apparatus to be fed data and to listen for updates. If you form a hierarchy with those mediators, then the UI becomes twice as brittle and hard to refactor, since you have to refactor two hierarchies. Picture the electrodes placed at various points around the skull and connected to an EEG, the tangled hierarchy is in the brain, but the updates from it are carried away to the machine in a nice orderly set of isolated parallel wires.

Have a look at the HelloFlash demo which, although it's Flash and not Flex will illustrate for you the idea of new items (multiple instances of the same item in this case) being added to the stage and having their mediators dynamically created.

Then have a look at the Slacker Flex demo which has deferred instantiation of different panels within a viewstack triggering the creation of the appropriate mediators. While they are all panels, they're assumed to be different custom components each with a specific mediator.

-=Cliff>



Logged
Steve
Newbie
*
Posts: 6


View Profile Email
« Reply #5 on: June 14, 2009, 11:24:06 »

Thanks Cliff, sorry but I can't find the demos anywhere - can you give me a pointer as to where I can find them, thanks
Logged
puremvc
Global Moderator
Hero Member
*****
Posts: 2871



View Profile WWW Email
« Reply #6 on: June 15, 2009, 05:14:20 »

Code -> AS3 -> Demos/Flex/Slacker
Code -> AS3 -> Demos/Flash/HelloFlash

-=Cliff>
Logged
Pages: [1]
Print