Search code examples
actionscript-3airgamepad-api

GameInput.DEVICE_ADDED not triggering at application startup


I'm posting this question because i'm having a little problem with the GameInput API in an adobe AIR desktop app. I tested the API in a test app and it worked just fine. However, when i added it to my real app (a game), it doesn't trigger anymore at startup.

Everything else works, and if i disconnect/reconnect the controller, everything works fine. However, the initial trigger of the callback function isn't working anymore.

Any idea why ? Here's what i do:

        if (GameInput.isSupported) //GAMEPADS SUPPORT
        {
            gameInput = new GameInput();
            gameInput.addEventListener(GameInputEvent.DEVICE_ADDED, controllerAdded);
            gameInput.addEventListener(GameInputEvent.DEVICE_REMOVED, controllerRemoved);
            gameInput.addEventListener(GameInputEvent.DEVICE_UNUSABLE, controllerProblem);
        }                           //GAMEPAD SUPPORT

    public function controllerAdded(e:GameInputEvent):void
    {
        var vec:Vector.<String> = new Vector.<String>();

        gamepad = GameInput.getDeviceAt(0);
        vec[0] = gamepad.getControlAt(0).id;
        gamepad.enabled = true;
        gamepad.sampleInterval = 10;
        gamepad.startCachingSamples(5, vec); // numSamples = 5
        for (var i:int = 0; i < gamepad.numControls; ++i)
            gamepad.getControlAt(i).addEventListener(Event.CHANGE, handleChangeEvent);
    }

I am guessing it could be a focus issue or something related but i really don't see why this would be happening. My app looks like this: Core (class called from swf and manages the whole app)

Screens (different classes that inherit movieclip but have logic inside, such as game, optionscreen, etc.)

The Gameinput api intialization is done in the core, after the instanciation of the object (using Event.ADDED_TO_STAGE).


Solution

  • Well it seems the GameInput API by Adobe is too unstable.

    I've decided to use AirControl instead and it works much better... I'm therefore closing this question.