Adobe Air - 键盘事件错误

发布于 2025-01-07 15:19:22 字数 560 浏览 4 评论 0原文

下面的代码抛出错误1046:未找到类型或不是编译时常量:KeyboardEvent。

有人知道为什么吗?

import flash.desktop.NativeApplication;
import flash.desktop.SystemIdleMode;
import flash.system.Capabilities;
import flash.system.System;

if (Capabilities.cpuArchitecture == "ARM")
{
NativeApplication.nativeApplication.addEventListener(KeyboardEvent.KEY_DOWN, handleKeys, false, 0, true);
}



function handleKeys(event:KeyboardEvent):void
{
    if (event.keyCode == Keyboard.BACK)
    {
        NativeApplication.nativeApplication.exit();
    }
}

The code below throws the error 1046: Type was not found or was not a compile-time constant: KeyboardEvent.

Does anybody know why?

import flash.desktop.NativeApplication;
import flash.desktop.SystemIdleMode;
import flash.system.Capabilities;
import flash.system.System;

if (Capabilities.cpuArchitecture == "ARM")
{
NativeApplication.nativeApplication.addEventListener(KeyboardEvent.KEY_DOWN, handleKeys, false, 0, true);
}



function handleKeys(event:KeyboardEvent):void
{
    if (event.keyCode == Keyboard.BACK)
    {
        NativeApplication.nativeApplication.exit();
    }
}

如果你对这篇内容有疑问,欢迎到本站社区发帖提问 参与讨论,获取更多帮助,或者扫码二维码加入 Web 技术交流群。

扫码二维码加入Web技术交流群

发布评论

需要 登录 才能够评论, 你可以免费 注册 一个本站的账号。

评论(1

心是晴朗的。 2025-01-14 15:19:22

您需要导入 KeyboardEvent 类。

这是否有效(请注意我添加的附加导入语句):

import flash.desktop.NativeApplication;
import flash.desktop.SystemIdleMode;
import flash.system.Capabilities;
import flash.system.System;
import flash.events.KeyboardEvent;
import flash.ui.Keyboard;

if (Capabilities.cpuArchitecture == "ARM")
{
NativeApplication.nativeApplication.addEventListener(KeyboardEvent.KEY_DOWN, handleKeys, false, 0, true);
}



function handleKeys(event:KeyboardEvent):void
{
    if (event.keyCode == Keyboard.BACK)
    {
        NativeApplication.nativeApplication.exit();
    }
}

You need to import the KeyboardEvent class.

Does this work (Note the additional import statement I've added):

import flash.desktop.NativeApplication;
import flash.desktop.SystemIdleMode;
import flash.system.Capabilities;
import flash.system.System;
import flash.events.KeyboardEvent;
import flash.ui.Keyboard;

if (Capabilities.cpuArchitecture == "ARM")
{
NativeApplication.nativeApplication.addEventListener(KeyboardEvent.KEY_DOWN, handleKeys, false, 0, true);
}



function handleKeys(event:KeyboardEvent):void
{
    if (event.keyCode == Keyboard.BACK)
    {
        NativeApplication.nativeApplication.exit();
    }
}
~没有更多了~
我们使用 Cookies 和其他技术来定制您的体验包括您的登录状态等。通过阅读我们的 隐私政策 了解更多相关信息。 单击 接受 或继续使用网站,即表示您同意使用 Cookies 和您的相关数据。
原文