问题
Im getting this annoying error and I can`t figure out what the problem might be...
TypeError: Error #1009: Cannot access a property or method of a null object reference.
at simplifyVirSys_fla::copyRightAthenaAcademy_1/initiateApp()
My main time line has two frames: frame1-the intro and frame2-the application itself
The intro is a movieclip. The code on the last frame of the intro mc goes like this:
addEventListener(Event.ENTER_FRAME, initiateApp);
function initiateApp(e:Event){
MovieClip(root).gotoAndStop(2);
}
So after playing the intro, it should jump to frame 2 of the main time line. And that`s where the output window goes crazy with the #1009 error.
回答1:
Try this:
addEventListener(Event.ADDED_TO_STAGE, this.ready);
function ready(e:Event) {
removeEventListener(Event.ADDED_TO_STAGE, ready);
addEventListener(Event.ENTER_FRAME, initiateApp);
}
function initiateApp(e:Event){
MovieClip(root).gotoAndStop(2);
}
回答2:
You can try validating the root.
addEventListener(Event.ENTER_FRAME, initiateApp);
function initiateApp(e:Event){
if (root)
MovieClip(root).gotoAndStop(2);
}
I don't understand why you are trying to go to the frame 2 using an EnterFrame Event. You simply must put a stage.gotoAndStop(2)
or MovieClip(root).gotoAndStop(2)
in the last frame of you animation.
来源:https://stackoverflow.com/questions/13457037/actionscript-3-0-typeerror