操作脚本 - TypeError:错误 #1009:无法访问空对象引用的属性或方法

发布于 2025-01-06 07:19:05 字数 1795 浏览 6 评论 0原文

首先,我只做了两周的动作脚本,对于大多数人来说这似乎是一项简单的任务,我深表歉意。在时间轴上,我有 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 技术交流群。

扫码二维码加入Web技术交流群

发布评论

需要 登录 才能够评论, 你可以免费 注册 一个本站的账号。

评论(1

萌能量女王 2025-01-13 07:19:05

尝试一下:

function Main()
{
  if(!stage){
    addEventListener(flash.events.Event.ADDED_TO_STAGE, onAddedToStage);
  }
  else{
    onAddedToStage(null);
  }
}
function onAddedToStage(e:Event):void
{
  if(hasEventListener(flash.events.Event.ADDED_TO_STAGE)){
    removeEventListener(flash.events.Event.ADDED_TO_STAGE, onAddedToStage);
  }

  Play_btn.addEventListener(MouseEvent.CLICK, playClicked);
  stop();
  back_btn.stage.addEventListener(MouseEvent.CLICK, backClicked);
  forward_btn.stage.addEventListener(MouseEvent.CLICK,forwardClicked);
}

Give this a try:

function Main()
{
  if(!stage){
    addEventListener(flash.events.Event.ADDED_TO_STAGE, onAddedToStage);
  }
  else{
    onAddedToStage(null);
  }
}
function onAddedToStage(e:Event):void
{
  if(hasEventListener(flash.events.Event.ADDED_TO_STAGE)){
    removeEventListener(flash.events.Event.ADDED_TO_STAGE, onAddedToStage);
  }

  Play_btn.addEventListener(MouseEvent.CLICK, playClicked);
  stop();
  back_btn.stage.addEventListener(MouseEvent.CLICK, backClicked);
  forward_btn.stage.addEventListener(MouseEvent.CLICK,forwardClicked);
}
~没有更多了~
我们使用 Cookies 和其他技术来定制您的体验包括您的登录状态等。通过阅读我们的 隐私政策 了解更多相关信息。 单击 接受 或继续使用网站,即表示您同意使用 Cookies 和您的相关数据。
原文