gpt4 book ai didi

actionscript-3 - ActionScript 3.0 : Addition of Document Class causes errors

转载 作者:行者123 更新时间:2023-12-02 10:55:12 26 4
gpt4 key购买 nike

我正在尝试使用我在Flash CS6中制作的游戏来学习Actionscript 3.0,并且文档类存在一些问题。最初,我有一个工作菜单,其中包含一些用于键盘事件和声音的脚本。我意识到我需要以可以从任何框架访问它们的方式存储一些变量,因此我创建了一个带有空类的Document Class并将游戏设置为引用它,现在菜单脚本正在生成编译器错误。我得到的错误是“1046:未找到类型或不是编译时常量:KeyboardEvent”,这对我来说没有任何意义,因为它可以正常工作。有人知道问题可能是什么吗?谢谢!

文件类别:

package  
{
import flash.display.MovieClip;
public class Main extends MovieClip
{

}
}

菜单脚本:
import flash.utils.getDefinitionByName;
import flash.ui.Keyboard;

stop();//Used to stay on the current frame

var selection:int = 0;//Will be used to determine which button has its "On" animation activated
var canMove:Boolean = true;

var menuSong:Sound = new MenuSong();
menuSong.play (0 , 9999);//Plays and loops(9999 times) menu theme

var menuMove:Sound = new MenuMove();
var menuSelect:Sound = new MenuSelect();

stage.addEventListener(KeyboardEvent.KEY_DOWN, move);//Calls move function when a key is pressed

function move(event:KeyboardEvent):void{//The line causing the error
if(canMove){
if(event.keyCode == 40){
selection = (selection + 1)%3;//Occurs when down key is pressed
menuMove.play();
}
else if(event.keyCode == 38){
selection = (selection + 2)%3;//Occurs when up key is pressed
menuMove.play();
}
else if(event.keyCode == 32){
canMove = false;
SoundMixer.stopAll();
menuSelect.play();
fadeOut.gotoAndPlay(1);
}

switch(selection){
case 0:
this.singlePlayer.gotoAndPlay("On");
this.multiplayer.gotoAndStop("Off");
this.credits.gotoAndStop("Off");
break;
case 1:
this.singlePlayer.gotoAndStop("Off");
this.multiplayer.gotoAndPlay("On");
this.credits.gotoAndStop("Off");
break;
case 2:
this.singlePlayer.gotoAndStop("Off");
this.multiplayer.gotoAndStop("Off");
this.credits.gotoAndPlay("On");
break;
}//All this just tells the selected button (Based on the selection variable)
//to play its "On" animation, and the other buttons to play their "Off" animation.
}
}

最佳答案

您需要在代码(菜单脚本)中使用flash.events.KeyboardEvent时将其导入。

为什么不将称为“菜单脚本”的脚本用作文档类?如果SWF的目标是菜单脚本代码中设计的目标,则应为文档类。

通过某种方式,如果您在代码中使用stage.addEventListener(KeyboardEvent.KEY_DOWN, move);,则必须导入flash.utils.KeyboardEvent。 Sound ( import flash.media.Sound)和SoundMixer(import flash.media.SoundMixer)同样。

关于actionscript-3 - ActionScript 3.0 : Addition of Document Class causes errors,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/16346853/

26 4 0
Copyright 2021 - 2024 cfsdn All Rights Reserved 蜀ICP备2022000587号
广告合作:1813099741@qq.com 6ren.com