Warning: file_get_contents(/data/phpspider/zhask/data//catemap/3/flash/4.json): failed to open stream: No such file or directory in /data/phpspider/zhask/libs/function.php on line 167

Warning: Invalid argument supplied for foreach() in /data/phpspider/zhask/libs/tag.function.php on line 1116

Notice: Undefined index: in /data/phpspider/zhask/libs/function.php on line 180

Warning: array_chunk() expects parameter 1 to be array, null given in /data/phpspider/zhask/libs/function.php on line 181

Warning: file_get_contents(/data/phpspider/zhask/data//catemap/9/google-cloud-platform/3.json): failed to open stream: No such file or directory in /data/phpspider/zhask/libs/function.php on line 167

Warning: Invalid argument supplied for foreach() in /data/phpspider/zhask/libs/tag.function.php on line 1116

Notice: Undefined index: in /data/phpspider/zhask/libs/function.php on line 180

Warning: array_chunk() expects parameter 1 to be array, null given in /data/phpspider/zhask/libs/function.php on line 181
Actionscript 3 添加多个按钮时遇到问题_Actionscript 3_Flash_Button_Screenshot - Fatal编程技术网

Actionscript 3 添加多个按钮时遇到问题

Actionscript 3 添加多个按钮时遇到问题,actionscript-3,flash,button,screenshot,Actionscript 3,Flash,Button,Screenshot,我试图在一个Flash文件中添加多个按钮(就像大多数Flash文件一样) 代码如下: stop(); import flash.events.MouseEvent; playButton.addEventListener(MouseEvent.CLICK, clickHandler); function clickHandler(event:MouseEvent):void{ var buttonName:String = event.currentTarget.name;

我试图在一个Flash文件中添加多个按钮(就像大多数Flash文件一样)

代码如下:

stop();

import flash.events.MouseEvent;

playButton.addEventListener(MouseEvent.CLICK, clickHandler);

function clickHandler(event:MouseEvent):void{
    var buttonName:String = event.currentTarget.name;
    if(buttonName == "playButton"){
        gotoAndStop(2);
    }
    else if(buttonName == "settingsButton"){
        gotoAndStop(3);
    }

}
所以现在的情况是播放按钮工作正常,但设置按钮不工作

另外,稍后我将把所有代码传输到一个ActionScript文件中,并在框架上使用
include
这个东西,此时一切都在进行中,所以不必告诉我时间轴上的代码不好(我不明白,有人能解释一下吗?没必要,这很好)

如果我只是这样做:

stop();

import flash.events.MouseEvent;

playButton.addEventListener(MouseEvent.CLICK, clickHandler);
settingsButton.addEventListener(MouseEvent.CLICK, clickHandler);

function clickHandler(event:MouseEvent):void{
    var buttonName:String = event.currentTarget.name;
    if(buttonName == "playButton"){
        gotoAndStop(2);
    }
    else if(buttonName == "settingsButton"){
        gotoAndStop(3);
    }

}
我得到错误1009:

TypeError: Cannot access a property or method of a null object reference.
    at Untitled_fla::MainTimeline/frame1()

你没有真正说明你的问题。但是,如果您想添加多个按钮,那么只需将事件侦听器添加到多个按钮中即可

playButton.addEventListener(MouseEvent.CLICK, clickHandler);
settingsButton.addEventListener(MouseEvent.CLICK, clickHandler);

那么,你有什么问题?你收到错误信息了吗?亲爱的上帝,我真蠢。这是我对帖子的编辑:编辑:完全忘了陈述我的问题。好的,现在的情况是播放按钮工作正常,但设置按钮不工作。对不起,我真是个白痴,我现在太爱面子了;(.亲爱的上帝,我真蠢。这是我对帖子所做的编辑:编辑:完全忘了说明我的问题。好吧,现在发生的事情是播放按钮工作正常,但设置按钮不工作。很抱歉,我是个白痴,我现在太爱面子了;(.您没有将事件侦听器添加到settingsButton,而且,实例名称区分大小写,因此请确保它是相同的。我按照您所说的做了,得到错误#1009,无法访问空对象引用的属性或方法。在Untitled_fla::main timeline/frame1()表示当前上下文中不存在
settingsButton
,您是否将该按钮放入容器中?像另一个movieclip或sprite一样?如果是,则必须为该按钮指定一个实例名称,并以以下方式访问它:
parentInstanceName.settingsButton