On another note, if you only need to listen to another class events simply register that class with the one you use. (like a controller)
Unless you need to dispatch an event afterwards.

import classToListen;
class myClass extends otherClass
{

    private var _classToListen:classToListen;
   function myClass(m:Model)
   {
       super();
   }

   public function register(registeredClass)
   {
       _classToListen = registeredClass;
_classToListen.addEventListener("onEvent", Delegate.create(this, eventHandler);
   }

   public function eventHandler(evtObj:Object)
   {
       //do stuff
   }
}


if you need to dispatch events then decorate with EventDispatcher as Jesse and Muzak recommand.

Alain

Muzak wrote:
As Jesse said, use the static way instead of initializing it in the constructor.
This serves 2 purposes:
- mixin only occurs once (rather than which each instance created)
- mixin occurs before the constructor is run

With that said, any reason why you're not decorating the super class with 
EventDispatcher?
When decorating the super class every subclass will have event dispatching 
(which is usually what you want).

regards,
Muzak

----- Original Message ----- From: "Jesse Graupmann" <[EMAIL PROTECTED]>
To: <[email protected]>
Sent: Saturday, June 09, 2007 1:57 AM
Subject: RE: [Flashcoders] AS2: EventDispatcher.initialize() andsuper()conflict?


I never use super() so I have no idea, but see what happens when you throw
the initialize in a static variable like;


class myClass extends otherClass
{
private static var EventDispatcherDependancy  =
mx.events.EventDispatcher.initialize ( myClass.prototype );
public var addEventListener:Function;
public var removeEventListener:Function;
public var dispatchEvent:Function;

public function myClass (m:Model) {
super();
}
}

_____________________________

Jesse Graupmann
www.jessegraupmann.com
www.justgooddesign.com/blog/
_____________________________



-----Original Message-----
From: [EMAIL PROTECTED]
[mailto:[EMAIL PROTECTED] On Behalf Of Merrill,
Jason
Sent: Friday, June 08, 2007 4:31 PM
To: [email protected]
Subject: [Flashcoders] AS2: EventDispatcher.initialize() and
super()conflict?

I have a class that has to call it's superclass in the constructor.
However, it also needs to initialize EventDispatcher to listen to
dispatch events that another class is listening to.  It seems, and I
could be wrong, that EventDispatcher does not work if it's not the first
thing in the constructor.  I thought someone had said once, or I read
it, that EventDispatcher has to be first in the constructor.  And of
course, probkem then is super() will not work if it's not first, so it
seems to be a catch-22.  Is this true regarding
EventDispatcher.initialize() and how to avoid?

code snippet:

          /*=========Constructor=========*/
public function MyClass(m:Model)
{
super(m);
EventDispatcher.initialize(this);
}

If this is OK then maybe something else is wrong in my code, I just
wanted to find out if maybe this is why the events aren't firing.

Thanks,



_______________________________________________
[email protected]
To change your subscription options or search the archive:
http://chattyfig.figleaf.com/mailman/listinfo/flashcoders

Brought to you by Fig Leaf Software
Premier Authorized Adobe Consulting and Training
http://www.figleaf.com
http://training.figleaf.com


_______________________________________________
[email protected]
To change your subscription options or search the archive:
http://chattyfig.figleaf.com/mailman/listinfo/flashcoders

Brought to you by Fig Leaf Software
Premier Authorized Adobe Consulting and Training
http://www.figleaf.com
http://training.figleaf.com

Reply via email to