Gamepad/Joystick support for Flash

[SIZE=3][SIZE=1]*Note to moderators: I tried posting this in another forum, but it didn’t show up. I can’t find any ‘pending’ section, or anything similar, so I’m reposting it here. If this causes a problem, just let me know.[/SIZE][/SIZE]**[SIZE=3]

Demo:[/SIZE]**[URL=“http://davidmercer.com/gamepad/”]
http://davidmercer.com/gamepad/

[SIZE=3]What this is:[/SIZE]
Using the GamepadAPI that has been tentatively adopted by the Mozilla and Chrome browsers, and the Gamepad.js library, I’ve developed a flash application that supports input from a controller, in-browser.

It is currently only working in the Chrome and Mozilla browsers, and only with developer flags, but it is working. Seeing as how the GamepadAPI is a W3C-considered specification, I think this is a safe avenue to begin development for.

This application is simply a proof-of-concept for utilizing javascript as a front-end to collect gamepad data and send it to a compiled flash .SWF file.

The application uses the ExternalInterface functionality provided by flash to interface with javascript. This functionality has been around since FlashMX, I believe. The breakthrough is the browsers adopting a specification for gamepad interfaces.

This application owes quite a bit to the Gamepad.js library, as it collects the gamepad inputs in a easily navigable array. Without it, this would have been a MUCH larger undertaking.

[SIZE=2]Anyway, I’m posting this here for two reasons: [/SIZE]

  1. I’ve been looking for a way to use gamepad input in a browser-based flash application since…well, as long as I can remember. There may be other ways to do this, but everything I’ve found requires separate applications on the user’s side, which I don’t think is best practices.
    This application, as of now, will still require some work on the user’s side, but it has two distinct advantages, in my opinion. First, it can be used with the consumer version of the Chrome browser that is currently released. And Second, if the GamepadAPI specification becomes more widely adopted, it may not require anything of the end user, in the future.

  2. This is just a proof-of-concept for the use of javascript as a front-end to capture gamepad data to use in flash applications. There could be a host of major problems like timing, duration-lag, and a ton of others. There no way I could thoroughly test the uses of this, so I thought it best to get it to the community as quickly as possible. The more gamepad-native apps we develop, the more we’ll know just how viable this is for gamepad support, and where its faults lie.

[SIZE=3]**Getting started: **[/SIZE]
So, there are a number of ways to get the demo underway, but I’m just going to tell you the quickest:

  1. Get an Xbox360 gamepad and plug it in. Once it has installed its drivers successfully, you can proceed.
  2. Download the newest release of Google Chrome. If you already have Chrome, the version you have should be fine. (Assuming you haven’t turned off automatic updating)
  3. In chrome, open a new tab and type in
chrome://flags
  1. In the list of flags, find the GamepadAPI flag, and select “Enabled”. (it’s near the bottom.) This will prompt you to restart. Do so.
  2. Navigate to the demo page. You should be able to use your xbox game pad to control the application!

Like I said, this is also available in Mozilla’s nightly builds, and with controllers that aren’t the Xbox controller, but this is just the fastest way to get it up and running. Visit the Gamepad.js site for more information on how to get this working in other browsers.

[SIZE=3]Source:[/SIZE]
If you’d like to download the source code, you can find it here.
Please poke around in there and let me know what you think. If you have an optimization or a better method for something, just let me know. I’d love to see some native-gamepad apps being developed to test functionality on this.

[SIZE=3]Resources:[/SIZE]
Gamepad.js
I can’t stress enough how important the Gamepad.js library is for this application. Please check it out and get to know how it works. And a big thanks to Scott for creating it!

GamepadAPI
This is just the specification information for the GamepadAPI. It’s not directly important, but any changes made to it will trickle down to the flash applications, so it’s a good idea to keep an eye on it.

ExternalInterface
The ExternalInterface functionality of flash is how we’re connecting the flash application to the javascript, so I thought I’d link to it. I learned how to utilize it from kirupa!

[SIZE=3]So yeah…[/SIZE]
That’s pretty much it. If you have some questions, I will try to answer them as best I can. Just let me know what you think.

Thanks!