I’ve got a really strange but - I think - really simple event flow problem with some AS3 classes that I’m writing. I wrote a class that extends EventDispatcher , called DispatchTest.
All the class does is listen for an event, called “test” . That’s it.
When it hears the event, it fires an event called “YO!”. I want “YO!” to be heard by instances of DispatchTest that reside in other classes, so they can in turn fire other events.
Here’s my problem. DispatchTest will always fire the “YO” event when called upon to do so, whether by a timer event, OR , an external custom event that I aim at the class.
HOWEVER, the YO event will only propogate out and be heard by other DispatchTest instances when fired by the Timer ! Using an external event will fire my custom “YO” event, but other instances of DispatchTest (instantiated in other classes) will NOT hear it ! They’ll only hear the timer fired event. Why on earth is this happening ? Here’s my code:
package
{
import flash.display.*;
import flash.utils.*;
import flash.events.*;
public class DispatchTest extends EventDispatcher{
public static var TEST_EVENT:String = "test";
public static var YO_EVENT:String = "YO";
public var timer:Timer;
public function DispatchTest() {
//timer = new Timer(1000,1);
//timer.addEventListener(TimerEvent.TIMER, sendYo);
//timer.start();
addEventListener("test", sendYo);
}
public function sendYo(event:Event):void {
dispatchEvent(new Event("YO"));
trace("DispatchTest has received the 'test' event, and is dispatching 'YO'.... ! ");
//trace(event.target);
}
}
}
As mentioned, the YO event will only be heard outside the constructor when the timer is
activated (removed from comments). Why is this happening ? I vaguely suspected it was
an event cloning issue, and read senocular’s run-down on the need to clone events. But I didn’t quite understand it and wanted to post this problem to see if anyone could shed some
light on this. THANK YOU!!
backwater