Search code examples
actionscript-3air

stage.mouseLock on AIR - Error #1056


I'm having a problem setting the stage.mouseLock property on AIR (3.2-3.4)

Compiling the following class in a FlashPlayer (11.2-11.4) Project works fine:

package  
{
    import flash.display.Sprite;
    import flash.display.StageDisplayState;
    import flash.events.KeyboardEvent;

    public class Main extends Sprite 
    {
        public function Main() 
        {
            stage.addEventListener(KeyboardEvent.KEY_DOWN, onKeyDown);
        }

        private function onKeyDown(event:KeyboardEvent):void 
        {
            stage.displayState = StageDisplayState.FULL_SCREEN;
            stage.mouseLock = true;
        }
    }
}

But when I try to compile the same class targeting AIR instead of FlashPlayer, the following error occurs:

Error #1056: Cannot create property mouseLock on flash.display.Stage.

I'm using AIR SDK Version: 3.4.0.2710 and FlashDevelop 4.1.0 as my IDE.

EDIT: Even after a clean install of FlashDevelop, downloading Flex SDK, AIR SDK, FlashPlayerDebugger from scratch, the problem persists.

EDIT 2: Thank you, TheDarkIn1978. After adding the -swf-version=17 AND editing the application.xml to use the correct version (3.4) manually, it worked... I'll try to find out if it is a bug in the latest FlashDevelop or AIR SDK (probably is in the FD)...


Solution

  • Your code is correct so i think you need to check to see if FlashDevelop is indeed targeting at least AIR SDK 3.2.

    First, comment out the offending code and trace the runtime version in your constructor:

    trace("AIR SDK Version: ", NativeApplication.nativeApplication.runtimeVersion);
    

    This should output at least:

    AIR SDK Version: 3.2.x.xxxx

    If not, you should check which Flex SDK (with AIR) FlashDevelop is targeting:

    Tools > Program Settings > AS3Context > Language > Installed Flex SDKs

    If you're unsure which version you have or you are targeting a version earlier than AIR SDK 3.2, you can download the latest AIR SDK (pre-merged with Flex SDK) from Adobe's Gaming site (Download the Adobe® AIR® SDK), save it to disk and link its location to FlashDevelop.

    enter image description here

    [EDIT]


    One last thing I forgot to mention: Make sure your project platform target is set to at least AIR 3.2 and that your project AIR SDK target settings aren't overriding your global AIR SDK target settings.

    Project > Properties

    enter image description here

    enter image description here

    [EDIT 2]


    Try manually overriding the target swf version and assign it to version 17.

    Project > Properties > Compiler Options > Advanced > Additional Compiler Options

    Add the following to the compiler options array:

    -swf-version=17

    enter image description here