Skip to main content
Known Participant
December 4, 2012
Answered

Exit Android App with external *actionscript.as* files

  • December 4, 2012
  • 4 replies
  • 1084 views

Hi, i'm trying to make this code work with a application that got 99% of code driving by external actionscript.as files;

In another app without any external call i mean no actionscript.as files, the code work very fine.

My goal is to shutdown any activity of the app when the user receive a call or something like that;

Many thanks in advance and sorry my english

Scene 1, Layer 'Layer 1', Frame 1, Line 14

1046: Type was not found or was not a compile-time constant: KeyboardEvent.

function handleActivate(event:Event):void

{

    NativeApplication.nativeApplication.systemIdleMode = SystemIdleMode.KEEP_AWAKE;

}

function handleDeactivate(event:Event):void

{

    NativeApplication.nativeApplication.exit();

}

function handleKeys(event:KeyboardEvent):void        ----- Line 14 -----

{

    if (event.keyCode == Keyboard.BACK)

    {

        NativeApplication.nativeApplication.exit();

    }

}

if (Capabilities.cpuArchitecture == "ARM")

{

    NativeApplication.nativeApplication.addEventListener(Event.ACTIVATE, handleActivate, false, 0, true);

    NativeApplication.nativeApplication.addEventListener(Event.DEACTIVATE, handleDeactivate, false, 0, true);

    NativeApplication.nativeApplication.addEventListener(KeyboardEvent.KEY_DOWN, handleKeys, false, 0, true);

}

This topic has been closed for replies.
Correct answer Colin Holgate

Make sure that your code has the import line:

import flash.events.KeyboardEvent;

4 replies

Colin Holgate
Colin HolgateCorrect answer
Inspiring
December 4, 2012

Make sure that your code has the import line:

import flash.events.KeyboardEvent;

HarpiolinAuthor
Known Participant
December 5, 2012

Look Mr. Colin, added the import flash.events.KeyboardEvent; and thats what i got:

Scene 1, Layer 'Layer 1', Frame 1,

Access of undefined property:

NativeApplication

SystemIdleMode

Keyboard

Capabilities

I'm addind this code inside Flash CS6, not via external.as

Colin Holgate
Inspiring
December 5, 2012

Each of those four things has an import line you will need to add. Look in the Flash help for each one, and the example code will show the import line you need.

Flash Pro knows all of the basic classes, you can get away with not adding the import line for most things, but these ones do need the import line.