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

标签 actionscript-3 compiler-errors flash-cs6 document-class

我正在尝试使用我在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/

相关文章:

actionscript-3 - 场景结束后停止音乐

xml - XJC 错误提示 "chameleon schema"

ios - 如何解决: Xcode Archive upload failed with error 22421

编译器想要 ";"- 我不知道为什么(在 C 中)

iphone - 在 iOS 6 Flash IPA 中带有黑色背景的 PNG

flash - 在 AS3 Flash/Flex 项目中嵌入 wav 文件?

actionscript-3 - 数学 - 沿直线每隔一段时间获取 x 和 y 坐标

actionscript-3 - 删除阵列AS3中每个对象的前一帧对象并使每个文件静音一个音频文件

actionscript-3 - 当给定角度和速度时,计算物体的轨迹

actionscript-3 - Windows 上有 Actionscript 3 的编译器吗?