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: renaming of reusing mediators, how???  (Read 3746 times)
uncleunvoid
Full Member
***
Posts: 27


View Profile Email
« on: October 22, 2009, 11:51:27 »

here is my conundrum:

I set up a basic mediator, one that basically just displays some clips. Lets call him/her ClipMediator. Now I want to re-use this one in my interface displaying different clips/content, which is fine on initialisation, as I just ahdn over different content.

Yet if anything changes due to user interaction, network process, etc. how can I retrieve one particular mediator and exchange the content?
Mediators are retrieved by NAME and the names of all my ClipMediators are 'ClipMediator' (i chose the same NAME as the class name)

how do I rename the NAME property of the mediator ?

of do I have to solve this in another way?
I cant go and produce 100 classes with unique names you know.(well i could but how about reusable code you know...)

anyone?
Logged
puremvc
Global Moderator
Hero Member
*****
Posts: 2871



View Profile WWW Email
« Reply #1 on: October 22, 2009, 01:58:47 »

Most of the time, you have only one instance of a given mediator and view component.

When you need multiplicity, you must give each mediator to have a unique name. Have a look at the HelloFlash demo; the HelloSprite and HelloSpriteMediator, and SpriteDataProxy.

http://trac.puremvc.org/Demo_AS3_Flash_HelloFlash

-=Cliff>
Logged
uncleunvoid
Full Member
***
Posts: 27


View Profile Email
« Reply #2 on: October 23, 2009, 12:41:24 »

yeah but not sure why my code doesnt work.

Here si what I do to rename the NAME prop:

:
public function BasicMediator(myTarget:Sprite,myData:Object,myName:String=null)
{


super(myName);
initContainer(myTarget);
ObjectUtils.synch(myData,this);
//addViewElement()
trace(NAME);
}

And here is what the example you gave does:

:
   public function HelloSpriteMediator( viewComponent:Object )
        {
            // pass the viewComponent to the superclass where
            // it will be stored in the inherited viewComponent property
            //
            // *** Note that the name of the mediator is the same as the
            // *** id of the HelloSprite it stewards. It does not use a
            // *** fixed 'NAME' constant as most single-use mediators do
            super( HelloSprite(viewComponent).id, viewComponent );
   
// Retrieve reference to frequently consulted Proxies
spriteDataProxy = facade.retrieveProxy( SpriteDataProxy.NAME ) as SpriteDataProxy;

// Listen for events from the view component
            helloSprite.addEventListener( HelloSprite.SPRITE_DIVIDE, onSpriteDivide );
           
        }


any idea why my version still doesnt show the new name?
Logged
uncleunvoid
Full Member
***
Posts: 27


View Profile Email
« Reply #3 on: October 23, 2009, 03:47:39 »

I added it to my code:

:
public function BasicMediator(myTarget:Sprite,tViewComponent)
{
trace(tViewComponent.id)
super(tViewComponent.id,tViewComponent);
trace(NAME);
}

but when I trace NAME it still is called 'Mediator'

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



View Profile WWW Email
« Reply #4 on: October 23, 2009, 03:40:37 »

That's because NAME is a constant. :)

Try:
:
trace( this.getMediatorName() );

-=Cliff>
Logged
uncleunvoid
Full Member
***
Posts: 27


View Profile Email
« Reply #5 on: October 24, 2009, 03:41:33 »

not sure that saves my problem.

mediators can only be retrieved by NAME not by mediator name , right?
so for example:

given I want a framework that delivers flexible layouts with a flexible number of texts on screen

each text only needs the same kind of mediator. as I dont know how many texts i will need, I want to simply re-use my TextMediator for all of them

giving now that one of the texts, say, to show some interaction related info, needs to change.

How would I be able to change this one meditor's text field , given that the mediator ntification interest will all be identical?
Logged
uncleunvoid
Full Member
***
Posts: 27


View Profile Email
« Reply #6 on: October 24, 2009, 04:26:32 »

why did noone tell me this little thing here:

so I can easily change the name via mediatorName and the retrieveMediator works also via mediatorName not just via NAME

so a simple:

:
mediatorName=myName != null?myName:NAME;
super(mediatorName,myViewComponent);
Logged
Pages: [1]
Print