
With binary sockets introduced in the player 9, you can do many things, I recently posted the SMTP Mailer class, which lets you send HTML mails with attached files through an SMTP connection, but what could be funny is playing with an analogic joystick in a flash game. There are many apps that lets you map the joystick inputs to the Keyboard, so that you can detect the player inputs with the Key class.
But you don't get analogic values, you just get left, right, up, down or so, with an analogic joystick plugged to the player you can get values oscillating between -100 (left) to 100 (right) or -20000 to 20000 if you want, you specify the offset, hence you get granular inputs, which results in a better user experience.
I developed a little tool in C# called "FlashStick", which manages joystick inputs through DirectX, and send the inputs to the Flash animation (behaving as a client), this is possible through the flash.net.Socket class available in AS3.
In Flash we receive a bytearray containing the joystick inputs, X and Y pad values, but also every button state, so that we can detect which button is pressed, next addition would be delivering an API so that every game developer could call methods like startVibrate() or calibrate() or assignKeys(), and talk to the Flash Joystick Controller, that could be cool, of course these are just experiments
Find here the sources
In case you don’t have .NET framework, you can download it here
Comments (36)
Nice one Thibault
and sincerly thanks for sharing the sources
This is cool but it was actually possible to do that in AS1 througth a Socket connection with a java server.
There were free tools for controling flash with midi interfaces.
yes it was possible to do it in AS1, but through the use of XMLSocket, so you would have used strings, which would consume more memory and bandwidth, with AS3 you use binary sockets, much more optimized.
Another thing, is that in DirectX you get bytearray’s when you call some methods like getButtons() on the device, with binary sockets you don’t wast time serializing the data, you just pass it through the wire, that way you win some time and memory
awesome ! a bit of the C# directx code would be nice too ! thx
Hi Benoit,
C# sources will be posted soon
Hello Thibault:
Any word as to when you will post C# source. Seeing how you did this would be great!!
Hi Thibault,
If you deployed something like this to a users desktop (swf + C# client) how would you handle firewall and sandbox security issues?
Assuming that the swf and C# client communicate via localhost, is this going to be a problem?
I’m doing on the same thing over COM port
Please could you share C# code
Hi there,
could you please re-upload the sources?
it now links to an non-existing file.
im looking forward to test these files
Hi Nick,
will post that tomorrow, sorry about that, server has been hacked
I’m updating and uploading everything back.
ah thats realy anoying..
had that too couple of days ago..
except in a much smaller thing
okay thank you for that, can i find the files where they used to be?
good luck with your server!
How is it going with your server?
cant wait to do some testing with my new xbox360 controller:D
Well the idea is great but…
the sources seem not to be available : error 404
Hey!
Could you please take a look at the source files? still a 404 error..:(
Hi!!!
Good idea this!!! but… please, could you re-upload the sources?
The link isn’t work
Or maybe some-one can send me to my personal e-mail: juanitoteleco@hotmail.com
Thank you so muck
could you please re-upload the sources?
or else maybe send them to my email (the one i filled in)
thanks a lot
Seems like all links are broken, or security issue.
Hi guys,
Sources are back online
I have also included the C# Sources for the socket server.
http://www.bytearray.org/wp-content/projects/flashstick/FlashStick%20v0.31.zip
kind regards,
Thibault
Thanks for reuploading, I wanted to check this out for awhile! Unfortunately the .exe doesn’t seem to want to detect my Xbox 360 controller. :-/
Thank you for reuploading!!
unfortunately, i have exactly the same problem here:( is there a way to get this working with the wireless x360 controller, or is this protected by microsoft?
regards Nick
btw, will there (in the final version) be 4 controller support, or will it only stay with one?
Nick
Hi, have you any tutorial about how to use your resoucre?
or… where i can to find helps to use it?
thanks a lot!!
i got same problem here and im using a normal usb joystick, doesnt detect anything
Is this open source?
Hi Wouter,
yep
cheers
Hi,
I’m looking for sources to connect bluetooth devices to Flash ?
Can you help me ?????
Thnaks.
Hi, I’ve never used C# prior to your code, so sorry…
I’m using MS’s Free C# compiler: Microsoft C# Express 2008.
I can compile and run the application, but when I do AutoDetect, I get this error: LoaderLock
LoaderLock was detected
Message: DLL ‘C:\WINDOWS\assembly\GAC\Microsoft.DirectX.DirectInput\1.0.2902.0__31bf3856ad364e35\Microsoft.DirectX.DirectInput.dll’ is attempting managed execution inside OS Loader lock. Do not attempt to run managed code inside a DllMain or image initialization function since doing so can cause the application to hang.
What can I do about it? I presume your code works, so what am I doing wrong?
I want to change a few things for your program, either enable autodetect on run, or command line parameters that do the same and set the range values at the same time.
Otherwise the executable that comes with your zip works great, but I need the above changes implemented.
Thanks.
That’s really cool, but we need joystick support that works in the browser – check out my NO JOY? campain here:
http://blog.iainlobb.com/2008/08/no-joy-my-campaign-for-joystick-and.html
This works perfectly on WinXP machine, however I cannot get it to work on Vista.
I installed DX9.0c and started flashstick. It detects the joystick, but the socket server doesn’t start. Does anyone have a solution to this?
i cant change the mouse speed cause the advertisement at the top the window is to large
what do i do?
Excellent piece of software, but just a little question, how would you parse a joystick throttle?? I’m using Logitech Attack 3.
thanks
Just chiming in with another couldn’t get it to detect my joystick under vista.
hi, nice work
is it possible to read other analoge Axis ? (I’m using a dualanaloge gamepad)
thanks,
Hi Thibault, Thanks for putting this together. Really appreciate you sharing the source.
I put in support for XBOX 360 controllers – up to four controllers at once with dual analogue. Check it out:
http://psibaspace.net.au/projects/
http://flash-gamestation.comuv.com
This is a best solution and work ok.
You must configure your joystick once and is stored in a data base. When you start the game, then start the joystick configuration. And of course in fullscreen mode. You can use the analog joystick to mouse control.
Downloaded your source code a moment ago, and I’m already able to connect my 360 controller to a test app in flash. Many thanks for posting such a useful sample.
Trackbacks/Pingbacks (5)
[...] What are these new features in AS3? One main excitement that I’m running into is the socket connections. AS2 allowed this for XML but now we can connect and read/send data in many new formats including binary. So this makes possible connections to SMTP/POP and other such things. Ok, build on that one step further with Adobe’s Apollo and you can create e-mail and instant messenger applications to run on your desktop. Remember the power of speed. These applications can be developed very quickly! Here’s another example of what the socket connection can be used for … joystick control in Flash. [...]
[...] to Thibault Imbert from ByteArray.org I was inspired to use the new binary sockets feature of Flash Actionscript 3 [...]
[...] er diese Kommunikation erfolgreich entwickelte, könnt ihr auch in diese Fall wieder in seinem Blog [...]
[...] analog joystick, so that there's enough room and resistance that the inner area means something. …Connecting an analog Joystick with FlashStick Connecting an analog Joystick with FlashStick … There are many apps that lets you map the joystick [...]
[...] [...]