Contact Me


Recent Posts


Categories


Archives


Tags

3d actionscript Actionscript 2 Actionscript 3 api APIs as2 as3 brand caching carousel channel code compress contest contract CSS Flash flv fp10 free freelance gadget gadgets gdata google JavaScript jquery mvc papervision papervision3d PHP player playlist puremvc pv3d search tube tutorial twitter video widget XML you youtube

Recent Comments

  • Ahmed: Can you put up an example?
  • Ahmed: Hmmm sorry this is a tough one but I don’t work with ASP.NET! Sorry!
  • Michael: Good example but one question… in all the slider skinning I see with Flex the thumb overruns the left...
  • venkata: Hi I am using OAuth to connect to youtube api. I got accessToken and TokenSecret for a particular user. Now...
  • Ahmed: Good old flexlib, what component are you using?

Links


Help end world hunger

Speeding Up PureMVC Development, Part 2: The Mediator

Update: I’ve updated the mediator class now, here’s the post: Speeding Up PureMVC Development, Part 2.1: The Mediator (2)

Following my post about speeding up PureMVC development regarding the view, I’m now moving on to part two of my series on PureMVC: The Mediator.

It’s handy if you understand and/or have used PureMVC before, if not, have a read of my tutorial on using and understanding PureMVC.

Extending the Mediator

As we know the mediator is very important, without it our views couldn’t interact with or be updated by our application. However, there are times when I do find that I’m just rewriting code between every mediator class, for example, when it came to handling events from the view, I found it annoying that sometimes I had to create handlers where all I wanted to do was just bubble the event via the mediator.

The solution is simple, just create a function that takes the event from the view and bubbles it up, much like:

1
2
3
4
public function sendEvent(event:SpriteEvent):void
{
    sendNotification( event.type, event.data );
}

Piece of pie eh? But then I found myself wanting to write this in ever mediator, but there’s no point to that, so I just extended the mediator class and then extend my class when writing a new mediator, here it is:

1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
package com.firestartermedia.lib.puremvc.patterns
{  
    import com.firestartermedia.lib.puremvc.events.SpriteEvent;
   
    import org.puremvc.as3.patterns.mediator.Mediator;

    public class Mediator extends org.puremvc.as3.patterns.mediator.Mediator
    {
        public function Mediator(name:String=null, viewComponent:Object=null)
        {
            super( name, viewComponent );
        }
       
        public function sendEvent(event:SpriteEvent):void
        {
            sendNotification( event.type, event.data );
        }  
    }
}

It’s not much of an extension, but it does help with the old coding. There are also further changes that I’m planning to make to the mediator class, for example, why do we have to use “listNotificationInterests()” and then duplicate code when setting “handleNotification()”? It’ll be much easier if we could combine these in a nice function, something I’ll hope to code up soon.

Tell me what you think.


Leave a Reply

Your comment:

Allowed tags: <a href="" title=""> <abbr title=""> <acronym title=""> <b> <blockquote cite=""> <cite> <code> <del datetime=""> <em> <i> <q cite=""> <strike> <strong>
Fork me on GitHub