views:

64

answers:

1

I have an <mx:Application> which contains a <mx:Module>. This module has several child modules. It also has some an instance of a class I have created. I am trying to have a method of this class dispatch an event that can be "heard" by the module and handled. This isn't happening.

Any ideas?

To be more clear, I am using 'dispatchEvent' to from inside a class method. There is an instance of this class in: mx.core.Application.myapplication.mymodule.myclass

It is the 'myclass.somefunction' that dispatches the event. I have a listener registered in 'mymodule'. Nothing happens when the function/method runs, however.

+2  A: 

If your class is a display object, you'll need to set your event to "bubble" up the display chain and listen for it in your application or module class. Events aren't application wide unless you use some sort of singleton or (like PureMVC) facade to "grab" all the events and perform actions based on those. So, when you create your new event to dispatch:

//Event(type:String, bubbles:Boolean = false, cancelable:Boolean = false)
var event:Event = new Event("custom_event_name", true);
dispatchEvent(event);

In your application you'll listen for it as the Application class is essentially the root of the swf.

addEventListener("custom_event_name", customEventHandler);

customEventHandler could then call functions in your module.

If you are dispatching from inside a class and the class isn't a display object, you could add an event listener to the instance of your class (mx.core.Application.myapplication.mymodule.myclass), not the module.

Typeoneerror