2012-02-21 103 views
1

下面的代碼會引發錯誤1046:未找到類型或不是編譯時常量:KeyboardEvent。Adob​​e Air - 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(); 
    } 
} 
+0

如果答案解決您的問題(如你在給你對此有何評論表示),請接受的答案。謝謝。 – CodeMouse92 2012-04-29 03:02:19

回答

3

您需要導入KeyboardEvent類。

這是否工作(注意額外的import語句我加的):

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(); 
    } 
} 
+0

謝謝。 這是缺少的:** import flash.ui.Keyboard ** – Tom 2012-02-21 13:21:42

+0

[編輯] ... nevermind ... – 2012-02-21 13:52:55