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
Flash 转到动作脚本3.0中的下一帧_Flash_Actionscript 3_Adobe - Fatal编程技术网

Flash 转到动作脚本3.0中的下一帧

Flash 转到动作脚本3.0中的下一帧,flash,actionscript-3,adobe,Flash,Actionscript 3,Adobe,我对AS 3.0有问题 当你点击一扇门时。您将移动到下一帧。 在下一帧中,我尝试了同样的方法。但它不起作用 代码如下: 框架1 stop(); deur1.addEventListener(MouseEvent.CLICK, frame2); function frame2(event:MouseEvent) { gotoAndStop(2) }// This part works. I am now in frame 2. 框架2: deur2.addEventL

我对AS 3.0有问题 当你点击一扇门时。您将移动到下一帧。 在下一帧中,我尝试了同样的方法。但它不起作用

代码如下:

框架1

stop();

deur1.addEventListener(MouseEvent.CLICK, frame2);
function frame2(event:MouseEvent)

    {
gotoAndStop(2)
        }// This part works. I am now in frame 2.
框架2:

deur2.addEventListener(MouseEvent.CLICK, frame3);
function frame3(event:MouseEvent)

    {
gotoAndStop(3)
        }
deur1=门1。deur2=门2
门是一个按钮。 当我运行这个项目时。我看到的是每一帧的所有帧

这是我得到的编译错误: 编译错误

场景1,“layer1”层第2帧第1行:1023

场景1,“layer1”层第2帧第1行:1021重复函数定义

场景1,“layer1”层第2帧第3行:1000对第2帧的不明确引用


MainTimeLine,Line2:1000对frame2的引用不明确。

由于函数使用的名称,因此会出现编译错误。“frame2”和“frame3”似乎是保留名称。尝试对函数使用更具描述性的名称,这将帮助您(和其他人)理解代码,这样您就不太可能遇到这样的错误

试试这个(我还修改了格式以提高可读性):

在第1帧上:

stop();

deur1.addEventListener(MouseEvent.CLICK, go_to_frame2);

function go_to_frame2(event:MouseEvent):void
{
  gotoAndStop(2)
}
在第2帧上:

deur2.addEventListener(MouseEvent.CLICK, go_to_frame3);

function go_to_frame3(event:MouseEvent):void
{
   gotoAndStop(3)
}

为什么不制作更通用的函数呢?如果在第一个帧中声明了函数,则可以从其他帧访问它们。像这样:

// Frame 1
function goPrevFrame(event : MouseEvent) : void
{
    nextFrame(); // or gotoAndStop(currentFrame +1);
}

function goNextFrame(event : MouseEvent) : void
{
    prevFrame(); // or gotoAndStop(currentFrame -1);
}

stop();
deur1.addEventListener(MouseEvent.CLICK, goNextFrame);



需要记住的一点是,您没有删除任何事件侦听器,因此应该使用弱引用

deur3.addEventListener(MouseEvent.CLICK, goNextFrame, false, 0, true);

您没有忘记停车();在你的框架2中,对吗?那不需要。和我一样:转到第二帧并停止(2)。非常感谢。现在这个很好用!我可以问一下为什么还要添加:Void吗?添加Void是为了让人们(和编译器)能够阅读函数行并知道这个函数将返回什么。在本例中为void,因为它不返回任何内容。它只需要一点点代码就可以结束了。例如,toString()返回一个字符串(显然),因此将写入
函数toString():String{return“hello”}
我会让其他人回答您:第三个答案的信息量更大
// Frame 3
stop();
deur3.addEventListener(MouseEvent.CLICK, goNextFrame);
deur3.addEventListener(MouseEvent.CLICK, goNextFrame, false, 0, true);