I have a custom event class
public class FFTDrawEvent extends Event {
public static const DRAW_EVENT:String = "drawEvent";
private var _param:Array = new Array();
public function FFTDrawEvent(type:String, __param:Array, bubbles:Boolean=true, cancelable:Boolean=false) {
_param = __param;
super(type, bubbles, cancelable);
}
public function get param():Array {
return _param;
}
}
This event is dispatched by a class, that extends EventDispatcher:
public class ToneGenerator extends EventDispatcher {
public function someFunction():void {
this.dispatchEvent(new FFTDrawEvent(FFTDrawEvent.DRAW_EVENT,_param));
}
Another class listen to this event. This class is extending SpriteVisualElement.
public class SpectrumVisualizer extends `SpriteVisualElement`:
{
public function SpectrumVisualizer()
{
this.addEventListener(FFTDrawEvent.DRAW_EVENT, draw);
}
Unfortunately this doesn’t work. The event is dispatched (returns with true), but the Event listener is never triggered.
Both class (Dispatcher & Listener) are Child class of a MXML application. Also listen to the event in the parent MXML application doens’t work. Listen to the event in the dispatching class itself somehow works.
I have to feeling that the EventDispatcher class is not the right one to dispatch events to a mxml application or respectivly AS classes, which extend/inherent from a MXML component class.
Anybody can help me with that?
You should listen for events on the dispatcher. In your case, an instance of
ToneGeneratoris dispatching the event andSpectrumVisualizeris listening – it wouldn’t work.That’s the only way it would work.
When you call
you are telling
thisobject to callthis.drawmethod whenever it (thethisobject) dispatches an event of typeFFTDrawEvent.DRAW_EVENT. Change it toNow you are telling
toneGenobject to callthis.drawmethod whenever it (thetoneGenobject) dispatches an event of typeFFTDrawEvent.DRAW_EVENT.You can also do the following from the parent mxml.
Call
specVis.drawmethod whenever thetoneGenobject dispatches an event of typeFFTDrawEvent.DRAW_EVENT.