Source Code: EventProxy

A couple months ago, Mike Chambers released an EventProxy class, which served to make delegating EventDispatcher events simpler. At the time, I meant to release my own EventProxy class with some extra functionality, but it slipped my mind until today when Phil reminded me of it.

My EventDispatcher works almost exactly the same as Mike’s, with 2 differences:


  1. It calls handleEvent on its target, as well as the specified function.

  2. It has an enabled property, that lets you temporarily disable the proxy


Nothing too major, but I find these capabilities handy, and thought others might as well.

You can download EventProxy by clicking here. It should be placed in the com.gskinner.events package.

You can see a brief usage example below. For a full description of how to use EventProxy, please see Mike’s post on the subject.

// import the EventProxy so we can refer to it by name:
import com.gskinner.events.EventProxy;
// create an instance of EventProxy, and tell it to call
// doStuff in this scope when triggered:
clickEventProxy:EventProxy = new EventProxy(this,"doStuff");
// register the EventProxy to listen for click events
// from the button:
myPushButton.addEventListener("click",clickEventProxy);
// this function will be called when the button is clicked.
function doStuff(p_evtObj:Object):Void {
trace("button clicked");
// stop it from firing again for now:
clickEventProxy.enabled = false;
}

Grant Skinner

The "g" in gskinner. Also the "skinner".

@gskinner

7 Comments

  1. Mike Britton May 7, 2004 at 12:49pm

    This is completely separate from GDispatcher, right?

  2. hi,can you tell me what’s the meaning of

    “clickEventProxy:EventProxy = new EventProxy(this,”doStuff”);

    “.

    because the Flash tell me “Syntax error”.And i changed it to “clickEventProxy= new EventProxy(this,”doStuff”);

    “.Everything gose well.I just want to know why.I’m from china,so my english is so poor:)

  3. “because the Flash tell me “Syntax error”.And i changed it to “clickEventProxy= new EventProxy(this,”doStuff”);”

    Are you using Flash MX and not MX 2004, as declaring a property in this way is ActionScript 2.0, using this code in Flash MX will cause an error (like you have recieved) as it’s ActionScript 1.0.

  4. this is my email: http://www.ashen23_rose@yahoo.com

    pls sent me a code and steps in hoe to make a Demo out of flash mx.

    thanx

    Ashen

  5. this is my email: http://www.ashen23_rose@yahoo.com

    pls sent me a code and steps in hoe to make a Demo out of flash mx.

    thanx….

    Ashen

  6. pls sent me a code and steps in how to make a Demo out of flash mx.

    thanx….

    Ashen

    this is my email: http://www.ashen23_rose@yahoo.com

  7. hey G, you may want to update the zip with your newer version, line 23 seems outdated, it is missing the check for “undefined”

    listener[(functionName!=undefined) ? functionName : p_evtObj.type](p_evtObj);

    Cheers

Comments are closed.