1 Attachment(s)
addEventListener of a linked class doesn't work!!!
Hey guys,
I have a small problem with linked custom classes [that do extend MovieClip] not receiving events sent by the document class. Here is the code:
Document class:
Code:
package {
import flash.display.MovieClip;
import flash.events.Event;
public class Main extends MovieClip {
public function Main() {
dispatchEvent(new Event("blah"));
trace("Main ");
}
}
}
Foo class:
Code:
package {
import flash.display.MovieClip;
import flash.events.Event;
public class Foo extends MovieClip {
function Foo() {
trace("Foo");
addEventListener("blah", workDarnIt);
}
function workDarnIt(evt:Event):void{
trace("got it in Foo");
}
}
}
Bar class:
Code:
package {
import Foo;
import flash.events.Event;
public class Bar extends Foo {
function Bar() {
super();
trace("Bar");
//addEventListener("blah", workDarnIt);
}
override function workDarnIt(evt:Event):void{
trace("got it in Bar");
}
}
}
The Bar class is linked to a simple square MovieClip that was placed on Stage during author time.
When I compile the .fla the it never traces "got it in bar" ?! It also never traces "got it in Foo" ?! It's as if dispatchEvent() function in the Main document class does nothing... I know for a fact that The Main class does fire an event, 'cause I tested it. But I don't understand why the Bar class doesn't hear the event "blah" from the Main? The constructors of the linked classes run before the Main() document class constructor. I know that, so why doesn't this work?
BTW: if i say stage.addEventListener() inside Bar class everything works properly. It's as if the linked Bar class is not part of DisplayList!!! How can this happen? (Bar extends Foo that extends MovieClip, and I can see the Bar square Movieclip on stage when movie runs.)
Please help! Thank you in advance.