嗨,我已经在网上搜索了几个小时,并没有找到解决我的问题的方法,我不知道如何解决它,因为我只是新手闪光所以,如果你知道任何可能有助于我只是评论下面请非常感谢所有帮助
所以这是代码
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)
}
}
这是错误
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()
答案 0 :(得分:1)
你使用gotoAndStop()
移动一个帧,同时你有定时器来引用除当前帧之外的其他帧上不存在的对象(5)。 gotoAndStop()
会触发先前当前帧的破坏,因此,一旦你转到另一帧,你的Hungry_bar
就会变为无效,但定时器仍会打勾,因为它们是独立于帧的,当它们触发定时器事件时,你的函数假设您的MC组件在它们不再存在时就在那里。当您通过gotoAndStop()
更改框架时,您应该停止计时器并删除他们的听众。