EventDispatcher uses the Decorator pattern, and technically adds methods to
whatever you pass in. Since you are running it in the constructor, you are
adding methods to the instance. You are better off adding them to the
class' prototype, so that only 4 methods are added to your class instead of
4 per instance. Everytime you make a new instance of your class, 4 new
methods are added to the instance, meaning 4 more functions in RAM vs. just
4 on the prototype, and all instances, 1 or million, all pointing to just
those same 4 in memory.
You use a static initializer to do this, it runs once, during the class
registration phase.
class YourClass
{
public var addEventListener:Function;
public var removeEventListener:Function;
private var dispatchEvent:Function;
private static var mixin:Void =
EventDispatcher.initialize(YourClass.prototype);
}
>From then on, you can use the functions as you have; this is just way more
efficient for RAM usage.
To your credit, a lot of base classes such as UIComponent, in both Flex,
Flash, and Flex 2 & ActionSript 3 utilize events "from yourself", so the:
addEventListener("mouseDown", this);
Will be more common.
----- Original Message -----
From: "Javier Tello" <[EMAIL PROTECTED]>
To: "Flashcoders mailing list" <[email protected]>
Sent: Sunday, November 13, 2005 10:25 AM
Subject: Re: [Flashcoders] dispatching events from a class
Yes ok Muzak, but for example, it's the way the Tween class were
implemented. It is like an onEnterFrame build in event, just to get
less code lines in the main movie.
I do not remember who, but someone discuss this issue, relating how to
implement the EventDispatcher class, and explaining to do it in the
constructor.
El 13/11/2005, a las 15:15, Muzak escribió:
> Delegate.create(this, this.eventHandler));
_______________________________________________
Flashcoders mailing list
[email protected]
http://chattyfig.figleaf.com/mailman/listinfo/flashcoders
_______________________________________________
Flashcoders mailing list
[email protected]
http://chattyfig.figleaf.com/mailman/listinfo/flashcoders