How to add and remove Mediators in a actionscript-3 puremvc app

Mar
30

So since PureMVC has updated twice and also I never talked about garbage collection of the app, I have refactored PurelyKuler to work with PureMVC 2.3. Thate are quite a few changes, some being:

  1. the framework is being ported to many languages like PHP, Ruby, Python, Coldfusion, C# and many others.
    [as]import org.puremvc.as3.interfaces.IFacade;
    import org.puremvc.as3.patterns.facade.Facade;[/as]
    as oppose to
    [as]import org.puremvc.interfaces.IFacade;
    import org.puremvc.patterns.facade.Facade;[/as]
  2. there is a new way to notify observers:
    [as]facade.sendNotification(PurelyKulerConstants.STARTUP, app);[/as]
    as oppose to
    [as]facade.notifyObserver(new Notification(PurelyKulerConstants.STARTUP, app))[/as]
  3. also the Mediators are can be named from outside the class, so you can have many instances of the class and remove specific instances and not all.public function PurelyKulerMediator(mediatorName:String = null, viewComponent:Object=null){
    _tf = new TextField();

    super(NAME, viewComponent);// the colorContainer
    }
    Those are just a few.

Alright back to PurelyKuler.

So if you look at the last example I did, it was just about getting data from a Proxy to a Mediator.

This time I’m adding garbage collection and using the new, to ver2.3, onRemove method in IMediator to delete all the ui and variables. Like this.
[as]override public function onRemove():void
{
vo.removeEventListener(MouseEvent.CLICK, changeColor);
vo.graphics.clear();
vo.parent.removeChild(_tf);

_tf = null;
_ka = null;
cc = undefined;
trace(“_tf: ” + _tf);
}[/as]
Alright enough typing, here it is. Click on a mediator name.

Source | PurelyKuler2

 

3 Responses to “How to add and remove Mediators in a actionscript-3 puremvc app”

  1. timm says:

    thanks for these PureMvc posts – They’re well commented and v helpful

  2. joshspoon says:

    you’re welcome!

  3. Rob McCardle says:

    Updated for Flash Develop & 2009

    http://www.robmccardle.com/wp/?p=40

    Cheers Josh

Leave a Reply