Tom
Tom

Reputation: 5974

Adobe Air - KeyboardEvent error

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

Upvotes: 1

Views: 1382

Answers (1)

Richard Walton
Richard Walton

Reputation: 4785

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

Upvotes: 3

Related Questions