Title: How you remove a specific Mediator? Post by: Oscar on September 21, 2007, 11:00:43 Hi,
when you want remove an Mediator, you use the "removeMediator()" method from the facade instance. As paramter he takes the name of the Mediator, for example: facade.removeMediator(HelloSpriteMediator.getMediatorName()); But what is, when you have more Objects of the same Mediator, and you want remove only one specific Mediator? For example:
This Code generate 10 Instances of "HelloSprite" Objects, and his Mediator, and put it in the stage Displaylist. Now you want remove the "helloSprite5" instance. To remove the "helloSprite5" DisplayObject, you can make this: var tmpSprite:HelloSprite = stage.getChildByName("helloSprite5"); But how you remove only his corresponding "HelloSpriteMediator"? Because, when you do this:
it would also remove the Mediators from the other instances, because all Mediators have the same Name, right? A Mediator has a static constant Name. So every Mediator has the same name. How you can now remove only an specific Mediator? Title: Re: How you remove a specific Mediator? Post by: puremvc on September 21, 2007, 12:08:35 Hi Oscar,
In most cases, the Mediator is not instantiated multiple times, and so the getMediatorName method may simply return the value of the Mediator's static constant NAME. However if multiple instances will be created and registered, then the getMediatorName method of the Mediator must return a unique id for that instance. Examine the code for the HelloFlash demo. In particular View the Source for the HelloSpriteMediator. In the HelloFlash demo all the sprites that get created get a unique ID, and consequently the HelloSpriteMediator's getMediatorName method looks like this: /** Hope this helps, -=Cliff> Title: Re: How you remove a specific Mediator? Post by: Oscar on September 21, 2007, 12:21:41 Thanks, that's a great Idea to solve this. :)
|