actionscript-3 - Actionscript 三个较旧的目标不起作用?

标签 actionscript-3 flash actionscript

当我的目标是 10.3 及更高版本时,此代码在 actionscript 3 中工作正常,但是当我的目标是 Flash Player 9 时,它给了我错误场景 1,

第 1 层,第 1 帧,第 7 行 1119:通过静态类型 Class 的引用访问可能未定义的属性 L。

任何人都知道我如何解决这个问题,以便它在 Flash Player 9 中工作?我已经尝试过更改键盘。(keycode#) 甚至尝试使用明显是 flash player 9 键码语法的东西?
但我尝试的一切都失败了。我在网上找不到解决方案,有人有任何想法吗?谢谢

var lDown:Boolean = false;
var sDown:Boolean = false;
var dDown:Boolean = false;
stage.addEventListener(KeyboardEvent.KEY_DOWN, onKeyBoardDown);
function onKeyBoardDown(e:KeyboardEvent):void
{
if (e.keyCode == Keyboard.L)
{
    lDown = true;
}
if (lDown == true)
{
    if (e.keyCode == Keyboard.S)
    {
        sDown = true;
    }
}
if (sDown == true)
{
    if (e.keyCode == Keyboard.D)
    {
        dDown = true;
    }
}
if (dDown == true)
{
    trace("ehhh");
    }
}

最佳答案

我对这个问题很感兴趣,因为查看文档,Keyboard and its constants 可从 Flash Player 9+ 中获得,但是就像你说的,当面向 Flash Player 9 时,我无法通过 A-Z 访问常量 Keyboard。但是我确实可以访问其他常量,例如F1HOMENUMPAD_*

一旦我将 Flash Player 版本更改为 10 或更高版本,我就可以访问 A-Z 常量。

我试图找到原因,但是在这个阶段,我只能假设文档无效,并且这些常量在 Flash Player 10 之前实际上不可用。

幸运的是,在这种情况下,解决方法非常简单:为 A-Z 的字符代码创建自己的常量:

package
{
    public class KeyCodes
    {

        public static const A:uint = 65;
        public static const B:uint = 66;
        public static const C:uint = 67;
        public static const D:uint = 68;
        public static const E:uint = 69;
        public static const F:uint = 70;
        public static const G:uint = 71;
        public static const H:uint = 72;
        public static const I:uint = 73;
        public static const J:uint = 74;
        public static const K:uint = 75;
        public static const L:uint = 76;
        public static const M:uint = 77;
        public static const N:uint = 78;
        public static const O:uint = 79;
        public static const P:uint = 80;
        public static const Q:uint = 81;
        public static const R:uint = 82;
        public static const S:uint = 83;
        public static const T:uint = 84;
        public static const U:uint = 85;
        public static const V:uint = 86;
        public static const W:uint = 87;
        public static const X:uint = 88;
        public static const Y:uint = 89;
        public static const Z:uint = 90;

    }
}

要使用此类,请将内容粘贴到与 FLA 位于同一目录中的 .as 文件中,然后:
if(e.keyCode == KeyCodes.A) // etc

我正在努力寻找造成这种情况的确切原因。

关于actionscript-3 - Actionscript 三个较旧的目标不起作用?,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/26472609/

相关文章:

actionscript-3 - getDefinitionByName 的替代方法

javascript - 从外部的 javascript 控制 Flash 播放器?

javascript - JavaScript 中的 ActionScript 调用函数

actionscript-3 - 在AS3中播放声音

flash - 如何在 ActionScript 中更改按钮 onclick?显示隐藏?

php - 一些使 AS3 和 ZendAMF 协同工作的帮助

java - 我可以将 .swf 文件转换为图像格式吗?

php - 通过PHP从MySQL到AS3检索信息

flash - 谷歌是反Flash的吗?

actionscript-3 - 相当于 "eval"的 Actionscript