I have a custom event that is dispatched when a slider is moved but I receive no event from inherited dispatcher class I created whereas I followed the same syntax as solution for My flash custom event doesn't trigger
Event class:
package {
import flash.events.Event;
public class CustomEvent extends Event
{
public static const ON_DISPATCHER_EVENT = "onDispatcherEvent";
public var value:Number;
public function CustomEvent(type:String, bubbles:Boolean=false, cancelable:Boolean=false):void
{
super(type, bubbles, cancelable);
}
}
}
Dispatcher:
package {
import flash.events.EventDispatcher;
import flash.events.Event;
public class CustomEventDispatcher extends EventDispatcher {
private var cEvent: CustomEvent;
public function CustomEventDispatcher() {
}
public function raiseEvent(_value:Number) {
cEvent = new CustomEvent(CustomEvent.ON_DISPATCHER_EVENT);
cEvent.value = _value;
dispatchEvent(cEvent);
}
}
}
Test class:
package {
import flash.display.*;
import flash.net.*;
import flash.events.*;
import fl.events.SliderEvent;
import fl.controls.Slider;
public class TestCustomEvent extends MovieClip {
private var cEvent: CustomEvent;
public function TestCustomEvent() {
addEventListener( Event.ADDED_TO_STAGE, init);
}
public function init( e:Event ):void {
removeEventListener( Event.ADDED_TO_STAGE, init );
this.addEventListener(CustomEvent.ON_DISPATCHER_EVENT,OnDispatcherEvent);
slider.addEventListener(SliderEvent.CHANGE,OnSliderEventChange);
}
public function OnDispatcherEvent(event:CustomEvent): void {
trace(event.value);
}
public function OnSliderEventChange(event:SliderEvent) {
cEvent = new CustomEvent(CustomEvent.ON_DISPATCHER_EVENT);
cEvent.value = event.value;
dispatchEvent(cEvent);
trace("hello");
}
}
}
I think your understanding of the event flow is a bit off. The answer I already gave in My flash custom event doesn't trigger (that I’m assuming you didn’t read) I think is the proper way to use custom
EventandIEventDispatcherobjects:[UPDATE]
[EDITED 08/04/2011 08:22]
I’ve modified the code to encapsulate all code involving dispatching and listening to/for events, as well as excuting event handlers, into another class(
EventDispatcherManager).