actionscript 3.0 TypeError

半腔热情 提交于 2019-12-02 08:21:41

问题


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

易学教程内所有资源均来自网络或用户发布的内容,如有违反法律规定的内容欢迎反馈
该文章没有解决你所遇到的问题?点击提问,说说你的问题,让更多的人一起探讨吧!