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

March 30th, 2008

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

Entry Filed under: PureMVC, actionscript, as3, flash

3 Comments Add your own

  • 1. timm  |  April 1st, 2008 at 9:26 am

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

  • 2. joshspoon  |  April 16th, 2008 at 6:27 pm

    you’re welcome!

  • 3. Rob McCardle  |  January 7th, 2009 at 12:08 pm

    Updated for Flash Develop & 2009

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

    Cheers Josh

Leave a Comment

Required

Required, hidden

*
To prove you're a person (not a spam script), type the security word shown in the picture. Click on the picture to hear an audio file of the word.
Click to hear an audio file of the anti-spam word

Some HTML allowed:
<a href="" title=""> <abbr title=""> <acronym title=""> <b> <blockquote cite=""> <cite> <code> <del datetime=""> <em> <i> <q cite=""> <strike> <strong> <pre lang="" line="" escaped="">

Trackback this post  |  Subscribe to the comments via RSS Feed