> My class that is adding the event listener is like this :
>_caption = new Caption();
> this.addEventListener(MeEvent.STOP,pauseStop);
> and from my calling class:
>var evt:MeEvent = new MeEvent(MeEvent.STOP);
 
This code doesn't really give enough detail to diagnose the problem.
What is the relevance of _caption? Is your "calling" (i.e., dispatching)
class actually calling dispatchEvent(evt)? It's best to post a complete
-- but as small as possible -- app that doesn't work, so we can
determine exactly what the problem is.
 
However, I suspect that the problem is that your listening class is
calling
 
    this.addEventListener(MeEvent.STOP, ...)
 
which means that it is listening to a STOP event which is dispatched by
'this' -- i.e., by the listener. But you want your listener to listen
for a STOP event dispatched by your dispatching class, so you want to
call
 
    instanceOfDispatchingClass.addEventListener(MeEvent.STOP, ...)
 
In other words, you add listeners to the dispatching object.

> I am implementing the IEventDispatcher class instead of extending the
EventDispatcher class

Why do you need to do that?

> My application uses all actionscript no flex.

IEventDispatcher and EventDispatcher are part of the Flash Player, not
part of the Flex Framework.

- Gordon

--------------------------

Gordon,

I'm just trying to finish a project and maybe I'm missing something. 

I've posted and I just am real dumbfounded why I am stuck and my 

listener's aren't working.

I've looked at some examples in a few texts and did some research and I 

am using your example below, I must be doing something silly. My 

project is based on a earlier post from you though I am implementing the


IEventDispatcher class instead of extending the EventDispatcher class

My application uses all actionscript no flex.

Sorry to ask for help directly. I am just stumped and trying to finish 

this project, which was going smoothly until this hiccup.

Thanks for your time,

Patrick

from your post...

Only the second class -- the one that dispatches the event by calling 

dispatchEvent() -- needs to extend EventDispatcher. You don't need to be


an EventDispatcher to listen to events.

The dispatching class must declare [Event] metadata if you want to write


listeners in MXML.

If your first class -- the one that listens -- is written in AS, you 

register for the event by calling addEventListener():

instanceOfDispatchingClass.addEventListener("someEventType", 

myEventHandler);

You would normally do this immediately after creating 

instanceOfDispatchingClass.

- Gordon


________________________________

From: [email protected] [mailto:[EMAIL PROTECTED] On
Behalf Of Patrick Lemiuex
Sent: Tuesday, February 27, 2007 5:15 PM
To: [email protected]
Subject: [flexcoders] Dispatching an event between 2 classes -



Flex People... Please help...

I have two classes fully loaded with inheritance... I'm trying to 
make an event from one class fire back at the class that called it 
like in my example below. Since, AS only supports single level 
inheritance, calling super is not available to me.

This has been a real block in understanding how to program events 
correctly, I keep running into this issue. I know how to extend the 
event Class and I know how to use composition to make a custom Event 
Dispatcher. I still can't seem to get my events to work with either 
situation.

My class that is adding the event listener is like this :

_caption = new Caption();
this.addEventListener(MeEvent.STOP,pauseStop);

and from my calling class:

var evt:MeEvent = new MeEvent(MeEvent.STOP);

I guess I am missing something fundamental in my approach to event 
management in actionscript

Thanks,
Patrick


 

Reply via email to