操作脚本 - TypeError:错误 #1009:无法访问空对象引用的属性或方法
首先,我只做了两周的动作脚本,对于大多数人来说这似乎是一项简单的任务,我深表歉意。在时间轴上,我有 2 帧,第一帧只有一个按钮可以转到下一个屏幕。第二个屏幕有 2 个按钮,可以向前或向后 1 帧。
我有 1 个名为 main 的类文件,用于所有操作脚本 该程序工作正常,直到我为 2 个框架上的 2 个按钮添加事件侦听器,然后我得到 TypeError:
错误#1009:无法访问空对象的属性或方法 参考。\Desktop\weather\Main.as:17]
调试会话终止。
17号线直达后停靠功能
package
{
import flash.display.*;
import flash.events.*;
public class Main extends MovieClip
{
public function Main()
{
// constructor code
Play_btn.addEventListener(MouseEvent.CLICK, playClicked);
stop();
back_btn.stage.addEventListener(MouseEvent.CLICK, backClicked);
forward_btn.stage.addEventListener(MouseEvent.CLICK,forwardClicked);
}
function playClicked(evt:MouseEvent):void
{
nextFrame();
}
function backClicked(evt:MouseEvent):void
{
if (currentFrame == 1)
{
gotoAndStop(totalFrames);
}
else
{
prevFrame();
}
}
function forwardClicked(evt:MouseEvent):void
{
if (currentFrame == totalFrames)
{
gotoAndStop(1);
}
else
{
nextFrame();
}
}
}
}
/*
back_btn.addEventListener(MouseEvent.CLICK, backClicked);
forward_btn.addEventListener(MouseEvent.CLICK, forwardClicked);
stop();
function backClicked(evt:MouseEvent):void
{
if(currentFrame == 1)
{
gotoAndStop(totalFrames);
}
else
{
prevFrame();
}
}
function forwardClicked(evt:MouseEvent):void
{
if(currentFrame == totalFrames)
{
gotoAndStop(1);
}
else
{
nextFrame();
}
}
First am only been doing action script 2weeks and apologise for what appears To be a easy task for most. On timeline I've 2 frames the first frame just has a button to go to the next screen.The second screen has a 2 buttons to allow to go forward or backward 1 frame.
I have 1 class file named main which am using for all the action script
the program works fine until I add the event listeners for the 2 buttons on the 2 frame then i get the the TypeError:
Error #1009: Cannot access a property or method of a null object
reference.\Desktop\weather\Main.as:17]
Debug session terminated.
Line 17 straight after the stop function
package
{
import flash.display.*;
import flash.events.*;
public class Main extends MovieClip
{
public function Main()
{
// constructor code
Play_btn.addEventListener(MouseEvent.CLICK, playClicked);
stop();
back_btn.stage.addEventListener(MouseEvent.CLICK, backClicked);
forward_btn.stage.addEventListener(MouseEvent.CLICK,forwardClicked);
}
function playClicked(evt:MouseEvent):void
{
nextFrame();
}
function backClicked(evt:MouseEvent):void
{
if (currentFrame == 1)
{
gotoAndStop(totalFrames);
}
else
{
prevFrame();
}
}
function forwardClicked(evt:MouseEvent):void
{
if (currentFrame == totalFrames)
{
gotoAndStop(1);
}
else
{
nextFrame();
}
}
}
}
/*
back_btn.addEventListener(MouseEvent.CLICK, backClicked);
forward_btn.addEventListener(MouseEvent.CLICK, forwardClicked);
stop();
function backClicked(evt:MouseEvent):void
{
if(currentFrame == 1)
{
gotoAndStop(totalFrames);
}
else
{
prevFrame();
}
}
function forwardClicked(evt:MouseEvent):void
{
if(currentFrame == totalFrames)
{
gotoAndStop(1);
}
else
{
nextFrame();
}
}
如果你对这篇内容有疑问,欢迎到本站社区发帖提问 参与讨论,获取更多帮助,或者扫码二维码加入 Web 技术交流群。

绑定邮箱获取回复消息
由于您还没有绑定你的真实邮箱,如果其他用户或者作者回复了您的评论,将不能在第一时间通知您!
发布评论
评论(1)
尝试一下:
Give this a try: