actionscript 3.0 TypeError

2019-02-28 08:26发布

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.

2条回答
来,给爷笑一个
2楼-- · 2019-02-28 09:00

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);
}
查看更多
神经病院院长
3楼-- · 2019-02-28 09:04

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.

查看更多
登录 后发表回答