valuetime
|
 |
« on: January 13, 2009, 06:15:51 » |
|
Since day one of using PureMVC, I have passed through a display object container as a Mediator constructor's viewComponent parameter (instead of creating a UI component before creating the mediator, as in the HelloFlash code example). A colleague pointed out that this is "incorrect". An example:
Say I have a command, which creates a Mediator:
SimpleCommand.as:
override public function execute(note:INotification):void { var stage:Stage = note.getBody() as Stage; facade.registerMediator(new TestMediator("test", stage)); }
And in the constructor of said Mediator, I create a display object:
SimpleCommand.as:
private var _sprite:Sprite; public function TestMediator(mediatorName:String = null, viewComponent:Object = null):void { super(mediatorName, viewComponent); _sprite = new Sprite(); viewComponent.addChild(_sprite); }
If I do it this way, I only put a reference to my UI component inside its mediator, not inside the command that creates it. Also, I can remove it from the stage, even delete it and re-create it if necessary.
Here's how I'm being told to do it:
SimpleCommand.as:
override public function execute(note:INotification):void { var stage:Stage = note.getBody() as Stage; var sprite:Sprite = new Sprite(); stage.addChild(sprite); facade.registerMediator(new TestMediator("test", sprite)); }
So, my question is... Why does it work this way? If I remove my TestMediator, I am still left with a sprite that has no direct references and no instance name, and therefore, no way to remove it from the stage!
Also, I much prefer to link my mediators to my UI components (which are intrinsically linked anyway) rather than putting them in stateless commands or unrelated mediators.
Am I totally missing something here?
Thanks.
|