Listening for an Event within a Custom Class?
i have file testclass.as:
package {
import flash.display.movieclip;
import flash.events.event;
import flash.events.eventdispatcher;
public class testclass extends movieclip{
public function testclass(){
//stuff
this.dispatchevent( new event( "initcomplete", true ) );
}
}
}
ie, it's basic class dispatches event tell me when it's finished initialising.
then in test.fla, i've done this:
var abc = new testclass();
abc.addeventlistener("initcomplete", startup);
function startup(e){
trace('success');
}
the dispatchevent sending - returns true when do trace( this.dispatchevent( new event( "initcomplete", true ) ));
when run test.fla, fails silently. function startup fails run.
couple things - in testclass don't need import eventdispatcher since extending movieclip, extends eventdispatcher. aside that, don't catch event because dispatching before add listener.
when do:
var abc = new testclass();
that runs constructor of testclass dispatches event... in next line add listener, event gone. remedy not dispatch event inside constructor.
More discussions in ActionScript 3
adobe
Comments
Post a Comment