After wanting for many years to be able to get full access to analogue gamepads in flash, a friend showed me the work Thibault Imbert has done to get standard gamepads into flash using a C# socket server and the new ByteArray functionality of actionscript 3.
I took his code and stripped out directx, brought in XNA to grab the XBOX 360 gamepad values and built in support for multiplayer and the ability to specify the polling interval and port number.
I also created an XBOX 360 controller manager class in as3. It manages all the network code for you. Inside the demo flash file you will find four movieclips on the root of the scene and each movieclip is a copy of a nastily hacked together demo showing how to use the manager.
Its quite simple to find out if player 1 has the X button pressed, you simply call
XBOX360Manager.getState(1).X;
To see the data structure of the object passed back by getState, simply check out the com.GamePads.XBOX360GamepadState.
I will work on making an equivalent as2 server, as I myself still like to use as2 for really cheap and nasty gameplay prototypes. Unfortunately without binary socket support in as2, I will need to generate xml, and use an xml socket. This will run slower and will take some time to code… so bare with me or beat me to it!
To download the files check out the projects page.
16 Comments for XBOX 360 Controllers in Adobe Flash
Dean | October 16, 2008 at 9:22 pm
Smeg | October 17, 2008 at 10:15 am
Wooo! I love it. Great job!
Consider the planet hacked!
Ricky Haggett | October 23, 2008 at 5:35 am
This works great in XP.
However, in Vista, I get error when trying to Run Server:
“An address incompatible with the requested protocol was used”.
And above the Run Server button, the Server IP Address seems to be garbage:
fe80::388f::33bd:3f57:fe9a%12.
Any chance of a Vista compatible version?
psiba | October 23, 2008 at 8:09 pm
Ricky:
It seems that Vista breaks the server because Vista defaults to IPV6 and the code isn’t built to support that.
I’ll resolve this and get back to you.
Carsten | December 5, 2008 at 6:34 am
Thanks, it’s great.
Is it possible in any way to send data back to the server for rumble?
That would be amazing
Joe | March 21, 2009 at 9:09 am
How did that IPv6 / IPv4 issue turn out? I’m trying to fix it in the source myself, but have little to no idea what I’m doing.
psiba | April 1, 2009 at 10:36 am
Vista is now supported.
Rumble might be a while off as I have a lot on my plate at the moment. Announcements to come…
Ryan | October 22, 2009 at 8:30 am
Sounds great… Just need to see if I can apply it to a PS3 controller instead!
mike boski | December 23, 2009 at 3:08 am
I still have the Vista problem
And above the Run Server button, the Server IP Address seems to be garbage:
fe80::388f::33bd:3f57:fe9a%12.
are the latest compiled files available.
mike boski | December 23, 2009 at 5:36 am
Also tried on XP with .Net 2.0 sp2 and XNA
but get an error:
System.IO.FileNotFoundException: The specified module could not be found. (Exception from HRESULT: 0×8007007E)
at FlashStick.MainClass.UpdateInputAndSendData(Object sender, EventArgs eArgs)
at System.Windows.Forms.Timer.OnTick(EventArgs e)
at System.Windows.Forms.Timer.TimerNativeWindow.WndProc(Message& m)
at System.Windows.Forms.NativeWindow.Callback(IntPtr hWnd, Int32 msg, IntPtr wparam, IntPtr lparam)
************** Loaded Assemblies **************
mscorlib
Assembly Version: 2.0.0.0
Win32 Version: 2.0.50727.3603 (GDR.050727-3600)
CodeBase: file:///c:/WINDOWS/Microsoft.NET/Framework/v2.0.50727/mscorlib.dll
—————————————-
XBOX360 Gamepad Server
Assembly Version: 1.0.3369.20792
Win32 Version: 1.0.3369.20792
CodeBase: file:///C:/Documents%20and%20Settings/Michael/Desktop/XBOX360inFlash/bin/Release/XBOX360%20Gamepad%20Server.exe
—————————————-
System.Windows.Forms
Assembly Version: 2.0.0.0
Win32 Version: 2.0.50727.3053 (netfxsp.050727-3000)
CodeBase: file:///C:/WINDOWS/assembly/GAC_MSIL/System.Windows.Forms/2.0.0.0__b77a5c561934e089/System.Windows.Forms.dll
—————————————-
System
Assembly Version: 2.0.0.0
Win32 Version: 2.0.50727.3053 (netfxsp.050727-3000)
CodeBase: file:///C:/WINDOWS/assembly/GAC_MSIL/System/2.0.0.0__b77a5c561934e089/System.dll
—————————————-
System.Drawing
Assembly Version: 2.0.0.0
Win32 Version: 2.0.50727.3053 (netfxsp.050727-3000)
CodeBase: file:///C:/WINDOWS/assembly/GAC_MSIL/System.Drawing/2.0.0.0__b03f5f7f11d50a3a/System.Drawing.dll
—————————————-
System.Configuration
Assembly Version: 2.0.0.0
Win32 Version: 2.0.50727.3053 (netfxsp.050727-3000)
CodeBase: file:///C:/WINDOWS/assembly/GAC_MSIL/System.Configuration/2.0.0.0__b03f5f7f11d50a3a/System.Configuration.dll
—————————————-
System.Xml
Assembly Version: 2.0.0.0
Win32 Version: 2.0.50727.3082 (QFE.050727-3000)
CodeBase: file:///C:/WINDOWS/assembly/GAC_MSIL/System.Xml/2.0.0.0__b77a5c561934e089/System.Xml.dll
—————————————-
************** JIT Debugging **************
To enable just-in-time (JIT) debugging, the .config file for this
application or computer (machine.config) must have the
jitDebugging value set in the system.windows.forms section.
The application must also be compiled with debugging
enabled.
For example:
When JIT debugging is enabled, any unhandled exception
will be sent to the JIT debugger registered on the computer
rather than be handled by this dialog box.
mike boski | December 23, 2009 at 2:47 pm
more info
when compiling in Visula C# 2008
I get this message
A first chance exception of type ‘System.Net.Sockets.SocketException’ occurred in System.dll
mike boski | December 23, 2009 at 4:14 pm
Tracked down the issue had to do a directX update.
I read this is a common problem on another webiste.
only took 8 hours but got it working.
This is awesome thanks so much.
Mike
psiba | December 24, 2009 at 12:44 am
If anyone feels like making this into a google code project, adding rumble or AS2 support themselves, i’m all for it.
Using XBox360 controllers in the Flash Player « Flash Life | April 7, 2010 at 2:37 pm
[...] It’s not pretty but it can be done, I wonder what kind of delays it has since the data is being passed around as a Byte Array from C#, check out the blog post. [...]
Kirill Rybin | April 26, 2010 at 3:42 am
Program is impressive!) But what about force feedback?) Is it possible to run from flash?
And i tested on standalone player and it works!) Code compiled with FlashDevelop and FlexSDK 3.5)


Woooahz!! Thats mega cooL!