如何在as3中修复错误1009

时间:2022-11-07 19:16:57

hi i have been searhing the net for hours and have not found a solution to my problem and i have no idea how to fix it as i am only new to flash so if you know anything that might help me just comment below please all help is greatly appreciated

嗨,我已经搜索了几个小时的网络,并没有找到我的问题的解决方案,我不知道如何解决它,因为我只是新的闪存,所以如果你知道任何可能有助于我只是评论下面请所有帮助是非常感激

so here is the code

所以这是代码

Quit.addEventListener(MouseEvent.CLICK, func2);

function func2(event:MouseEvent):void
{
    gotoAndStop(2);
}

Help.addEventListener(MouseEvent.CLICK, func4);

function func4(event:MouseEvent):void
{
    gotoAndStop(4);
}

var myTimer:Timer = new Timer(2000,0);
myTimer.addEventListener(TimerEvent.TIMER, timerListener);
function timerListener(e:TimerEvent):void {
Hungry_bar.scaleX-=0.05;
if(Hungry_bar.scaleX<=0.05){
        gotoAndStop(12)
    }
}
myTimer.start();

var myTimer2:Timer = new Timer(3000,0);
myTimer.addEventListener(TimerEvent.TIMER, timerListener2);
function timerListener2(e:TimerEvent):void {
Fun_bar.scaleX-=0.05;
if(Fun_bar.scaleX<=0.05){
        gotoAndStop(13)
    }
}
myTimer2.start();

Feed.addEventListener(MouseEvent.CLICK,feed)
function feed(e:MouseEvent){
    Hungry_bar.scaleX+=0.05
    if(Hungry_bar.scaleX>=1.5){
        gotoAndStop(14)
    }
}

Fun.addEventListener(MouseEvent.CLICK,happy)
function happy(e:MouseEvent){
    Fun_bar.scaleX+=0.05
    if(Fun_bar.scaleX>=1.5){
        gotoAndStop(15)
    }
}

And here is the error

这是错误

TypeError: Error #1009: Cannot access a property or method of a null object reference.
at petgame_fla::MainTimeline/timerListener()[petgame_fla.MainTimeline::frame5:19]
at flash.utils::Timer/_timerDispatch()
at flash.utils::Timer/tick()

TypeError: Error #1009: Cannot access a property or method of a null object reference.
at petgame_fla::MainTimeline/timerListener2()[petgame_fla.MainTimeline::frame5:29]
at flash.utils::Timer/_timerDispatch()
at flash.utils::Timer/tick()

1 个解决方案

#1


1  

You use gotoAndStop() to move off a frame, in the meantime you have timers that refer to objects that do not exist on other frames than your current frame (5). gotoAndStop() triggers destruction of previously current frame, thus, once you go to another frame, your Hungry_bar becomes void, but timers still tick, because they are frame independent, and when they trigger the timer event, your functions assume that your MC's components are there while they no longer are in place. You should stop the timers and remove their listeners when you change the frame via gotoAndStop().

你使用gotoAndStop()来移动一个帧,同时你有定时器来引用除当前帧之外的其他帧上不存在的对象(5)。 gotoAndStop()会触发先前当前帧的破坏,因此,一旦你转到另一帧,你的Hungry_bar就会变空,但是定时器仍然会打勾,因为它们是独立于帧的,当它们触发定时器事件时,你的函数会假设你的MC的组件他们不在的时候在那里。当您通过gotoAndStop()更改帧时,应该停止计时器并删除它们的侦听器。

#1


1  

You use gotoAndStop() to move off a frame, in the meantime you have timers that refer to objects that do not exist on other frames than your current frame (5). gotoAndStop() triggers destruction of previously current frame, thus, once you go to another frame, your Hungry_bar becomes void, but timers still tick, because they are frame independent, and when they trigger the timer event, your functions assume that your MC's components are there while they no longer are in place. You should stop the timers and remove their listeners when you change the frame via gotoAndStop().

你使用gotoAndStop()来移动一个帧,同时你有定时器来引用除当前帧之外的其他帧上不存在的对象(5)。 gotoAndStop()会触发先前当前帧的破坏,因此,一旦你转到另一帧,你的Hungry_bar就会变空,但是定时器仍然会打勾,因为它们是独立于帧的,当它们触发定时器事件时,你的函数会假设你的MC的组件他们不在的时候在那里。当您通过gotoAndStop()更改帧时,应该停止计时器并删除它们的侦听器。