Okay, I’m trying to create a job queue type of system that uses event bubbling so that events can be dispatched from multiple locations and bubble up to a front controller.
For some reason my EventHandler is never being called:
OUTPUT:
DataPack Constructed
Custom Event Constructed
EventTransporter Constructed
Dispatching event type: _dataevent
Does anyone see anything terribly wrong here?
TestEvents.as
package {
import flash.display.Sprite;
public class TestEvents extends Sprite
{
public function TestEvents()
{
addEventListener(CustomEvent.DATA_EVENT, onCustomEvent);
var myCaller:EventCaller = new EventCaller();
var myData:DataPack = new DataPack([1,2,3,4,5]);
var event:CustomEvent = new CustomEvent(CustomEvent.DATA_EVENT, myData);
var holder:EventTransporter = new EventTransporter(event);
myCaller.callEvent(holder);
}
private function onCustomEvent(event:CustomEvent):void
{
trace("onCustomEvent data: "+event.data);
}
}
}
DataPack.as
package
{
public class DataPack
{
private var _stuff:Array;
public function DataPack(ary:Array)
{
trace("DataPack Constructed");
_stuff = ary;
}
public function get stuff():Array { return _stuff }
}
}
EventCaller.as
package
{
import flash.events.EventDispatcher;
[Event(name="_dataevent", type="CustomEvent")]
public class EventCaller extends EventDispatcher
{
public function EventCaller() {}
public function callEvent(holder:EventTransporter):void
{
trace("Dispatching event type: "+holder.event.type);
dispatchEvent(holder.event);
}
}
}
EventTransporter.as
package
{
public class EventTransporter
{
private var _event:CustomEvent;
public function EventTransporter(event:CustomEvent)
{
trace("EventTransporter Constructed");
_event = event;
}
public function get event():CustomEvent { return _event }
}
}
CustomEvent.as
package
{
import flash.events.Event;
public class CustomEvent extends Event
{
public static const DATA_EVENT:String = "_dataevent";
private var _data:DataPack;
public function CustomEvent(type:String, data:DataPack)
{
trace("Custom Event Constructed");
super(type, true);
_data = data;
}
public function get data():DataPack { return _data }
}
}