chrisflynn
12-18-2008, 04:59 PM
Hi all
I have an event class that looks like this
package {
import flash.events.Event;
import flash.events.EventDispatcher;
public class FinishedEvent extends EventDispatcher{
public static const SOMETHING_FINISHED:String = "somethingFinished";
public function FinishedEvent(){
}
public function finished():void{
trace("finished() called");
dispatchEvent(new Event(SOMETHING_FINISHED));
}
}
}
I have another class that triggers that Finished method in the Finished_Event
package {
import flash.display.Sprite;
import FinishedEvent;
public class Class1 extends Sprite{
public var finishedEvent:FinishedEvent;
...
// Trigger finished method
public function finalize():void{
finishedEvent.finished();
}
...
}
}
Now that finished method does get called, I know by the trace i put there.
But how do I get another class to "hear" that event call. I would think I could do this:
package {
import flash.display.Sprite;
import FinishedEvent;
public class Class2 extends Sprite{
private var _finishedListener:FinishedEvent;
public function Class2(){
_finishedListener = new FinishedEvent();
_finishedListener.addEventListener(FinishedEvent.S OMETHING_FINISHED, finalize);
}
public function finalize(){
trace("finalize triggered");
}
}
}
But no matter what i do, I can't fire that finalize method.
So I'm missing something here. Is there a way for one class to trigger an Event class that another class, or many other classes, could respond?
Any help is always appreciated.
Thanks again
Chris
I have an event class that looks like this
package {
import flash.events.Event;
import flash.events.EventDispatcher;
public class FinishedEvent extends EventDispatcher{
public static const SOMETHING_FINISHED:String = "somethingFinished";
public function FinishedEvent(){
}
public function finished():void{
trace("finished() called");
dispatchEvent(new Event(SOMETHING_FINISHED));
}
}
}
I have another class that triggers that Finished method in the Finished_Event
package {
import flash.display.Sprite;
import FinishedEvent;
public class Class1 extends Sprite{
public var finishedEvent:FinishedEvent;
...
// Trigger finished method
public function finalize():void{
finishedEvent.finished();
}
...
}
}
Now that finished method does get called, I know by the trace i put there.
But how do I get another class to "hear" that event call. I would think I could do this:
package {
import flash.display.Sprite;
import FinishedEvent;
public class Class2 extends Sprite{
private var _finishedListener:FinishedEvent;
public function Class2(){
_finishedListener = new FinishedEvent();
_finishedListener.addEventListener(FinishedEvent.S OMETHING_FINISHED, finalize);
}
public function finalize(){
trace("finalize triggered");
}
}
}
But no matter what i do, I can't fire that finalize method.
So I'm missing something here. Is there a way for one class to trigger an Event class that another class, or many other classes, could respond?
Any help is always appreciated.
Thanks again
Chris