如何修复 as3 中的错误 1009
how to fix error 1009 in as3
您好,我已经在网上搜索了几个小时,但没有找到解决我的问题的方法,而且我不知道如何解决它,因为我只是 Flash 的新手,所以如果您知道任何可能对我有帮助的信息,请发表评论非常感谢以下所有帮助
所以这是代码
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()
您使用 gotoAndStop()
离开帧,与此同时,您有计时器引用当前帧 (5) 以外的其他帧上不存在的对象。 gotoAndStop()
触发对先前当前帧的破坏,因此,一旦您转到另一个帧,您的 Hungry_bar
将变为无效,但计时器仍会滴答作响,因为它们与帧无关,并且当它们触发计时器事件时,您的功能假定您的 MC 的组件存在,但它们不再存在。当您通过 gotoAndStop()
.
更改框架时,您应该停止计时器并移除它们的侦听器
您好,我已经在网上搜索了几个小时,但没有找到解决我的问题的方法,而且我不知道如何解决它,因为我只是 Flash 的新手,所以如果您知道任何可能对我有帮助的信息,请发表评论非常感谢以下所有帮助
所以这是代码
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()
您使用 gotoAndStop()
离开帧,与此同时,您有计时器引用当前帧 (5) 以外的其他帧上不存在的对象。 gotoAndStop()
触发对先前当前帧的破坏,因此,一旦您转到另一个帧,您的 Hungry_bar
将变为无效,但计时器仍会滴答作响,因为它们与帧无关,并且当它们触发计时器事件时,您的功能假定您的 MC 的组件存在,但它们不再存在。当您通过 gotoAndStop()
.