Dec
8
EventManager Example

Going to keep this short for now but I wanted to upload some example files for the EventManager to help anyone having trouble understanding it or getting it working.  I’ll post more soon about any specific questions people have but for now I’ve got to run and earn my rent money.

Here are the example files that use the classes from the tutorial:

EventManagerExample.zip

filed under: Misc | permalink

3 Responses to “EventManager Example”

  1. dudan Says:
    January 11th, 2009 at 6:31 pm

    Great tut!
    How would I reference the child object that dispatched the event from within the parent object that was listening?

    e.g. with a standard listener event you can do:

    function ($Event:Event):void{
    trace($Event.target.parent); //Return the object’s reference.
    }

    Cheers,

    dudan

  2. dudan Says:
    January 12th, 2009 at 5:22 am

    A way I’ve found to reference the object that fired the event is to pass data with the custom event.
    I don’t like this way though, as it breaks encapsulation.
    I’m not sure if there’s a way of actually passing a pointer/reference to an object like in C++ – I didn’t think that was possible in AS3…?

    This is what I was looked at to modify the custom event to pass data: http://flexcomps.wordpress.com/2008/04/29/dispatching-custom-events-in-as3-with-data-or-object/

    There must be a betta way?

    dudan

  3. dudan Says:
    January 13th, 2009 at 6:50 am

    ok…
    To retain encapsulation I just stuck a getter on ma custom event:

    public function get Info():*{
    var TempInfo:* = _PassedInfo;
    return TempInfo;
    }

    The OOP Gods are now happy!

    So now to get whatever info is passed to the event I just use $Event.Info e.g.

    private function TriggeredEvent($Event:MaCustomEvent):void{
    trace($Event.Info);
    }

    and when dispatching I pass whatever I want to know:
    dispatchEvent(new MaCustomEvent(MaCustomEvent.ONCLICK, “U KNOWS IT WERKS!”)

    dudan

Leave a Reply

You must be logged in to post a comment.

© 2010 pajamacode | Theme by DemusDesign, Theme Lab, and Search Optimization | Powered by WordPress