Connecting an analog Joystick with FlashStick

FlashStick

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 (40)

  1. Foxy wrote:

    Nice one Thibault :)

    and sincerly thanks for sharing the sources :)

    Tuesday, January 2, 2007 at 2:34 am #
  2. FS wrote:

    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.

    Tuesday, January 2, 2007 at 11:39 am #
  3. thibault.imbert wrote:

    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 ;)

    Tuesday, January 2, 2007 at 11:47 am #
  4. awesome ! a bit of the C# directx code would be nice too ! thx

    Wednesday, January 3, 2007 at 1:19 am #
  5. thibault.imbert wrote:

    Hi Benoit,

    C# sources will be posted soon ;)

    Wednesday, January 3, 2007 at 11:04 am #
  6. musr wrote:

    Hello Thibault:
    Any word as to when you will post C# source. Seeing how you did this would be great!!

    Wednesday, April 4, 2007 at 11:08 am #
  7. ChuChu wrote:

    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?

    Thursday, June 21, 2007 at 10:15 pm #
  8. VOOV wrote:

    I’m doing on the same thing over COM port
    Please could you share C# code

    Sunday, July 8, 2007 at 7:54 pm #
  9. Nick wrote:

    Hi there,
    could you please re-upload the sources?
    it now links to an non-existing file.
    im looking forward to test these files

    Monday, September 10, 2007 at 10:34 pm #
  10. Thibault Imbert wrote:

    Hi Nick,

    will post that tomorrow, sorry about that, server has been hacked :(

    I’m updating and uploading everything back.

    Tuesday, September 11, 2007 at 2:49 am #
  11. Nick wrote:

    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!

    Monday, September 17, 2007 at 10:22 pm #
  12. Nick wrote:

    How is it going with your server?
    cant wait to do some testing with my new xbox360 controller:D

    Monday, October 1, 2007 at 10:53 pm #
  13. ali wrote:

    Well the idea is great but…
    the sources seem not to be available : error 404

    Tuesday, October 2, 2007 at 10:29 am #
  14. Nick wrote:

    Hey!
    Could you please take a look at the source files? still a 404 error..:(

    Wednesday, October 17, 2007 at 11:44 am #
  15. ChodaBoy wrote:

    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 :D

    Monday, October 22, 2007 at 2:25 pm #
  16. Nick wrote:

    could you please re-upload the sources?
    or else maybe send them to my email (the one i filled in)

    thanks a lot

    Tuesday, November 20, 2007 at 2:09 pm #
  17. Seems like all links are broken, or security issue.

    Tuesday, November 27, 2007 at 3:23 am #
  18. Thibault Imbert wrote:

    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

    Tuesday, November 27, 2007 at 9:50 pm #
  19. Ken wrote:

    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. :-/

    Friday, November 30, 2007 at 7:00 pm #
  20. Nick wrote:

    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

    Saturday, December 22, 2007 at 11:46 pm #
  21. Nick wrote:

    btw, will there (in the final version) be 4 controller support, or will it only stay with one?

    Nick

    Saturday, December 22, 2007 at 11:57 pm #
  22. José Luis wrote:

    Hi, have you any tutorial about how to use your resoucre?

    or… where i can to find helps to use it?

    thanks a lot!!

    Thursday, January 10, 2008 at 11:40 pm #
  23. T wrote:

    i got same problem here and im using a normal usb joystick, doesnt detect anything :(

    Thursday, January 31, 2008 at 10:08 pm #
  24. Wouter wrote:

    Is this open source?

    Thursday, March 6, 2008 at 4:36 pm #
  25. Thibault Imbert wrote:

    Hi Wouter,

    yep :)

    cheers ;)

    Thursday, March 6, 2008 at 4:38 pm #
  26. actaruss wrote:

    Hi,
    I’m looking for sources to connect bluetooth devices to Flash ?
    Can you help me ?????

    Thnaks.

    Wednesday, March 12, 2008 at 11:03 pm #
  27. Chuck wrote:

    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.

    Friday, March 28, 2008 at 12:28 am #
  28. Iain wrote:

    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

    Monday, September 8, 2008 at 2:15 pm #
  29. Gerald wrote:

    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?

    Friday, October 24, 2008 at 9:35 am #
  30. john wrote:

    i cant change the mouse speed cause the advertisement at the top the window is to large
    what do i do?

    Friday, November 28, 2008 at 7:13 am #
  31. Daniel wrote:

    Excellent piece of software, but just a little question, how would you parse a joystick throttle?? I’m using Logitech Attack 3.

    thanks

    Sunday, December 21, 2008 at 8:52 am #
  32. wg wrote:

    Just chiming in with another couldn’t get it to detect my joystick under vista.

    Tuesday, July 7, 2009 at 11:56 pm #
  33. psyship wrote:

    hi, nice work ;)
    is it possible to read other analoge Axis ? (I’m using a dualanaloge gamepad)

    thanks,

    Tuesday, September 1, 2009 at 6:07 pm #
  34. Simon wrote:

    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/

    Saturday, September 12, 2009 at 8:09 am #
  35. jose wrote:

    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.

    Wednesday, April 14, 2010 at 11:11 pm #
  36. Banksy wrote:

    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.

    Sunday, June 6, 2010 at 11:35 pm #
  37. Wazar wrote:

    hi, very nice
    am an actionscript 3 programer,
    i want to ask a favour, am not good with socket things, can you put a simple example of connecting joystick
    to a simple swf to control a simple movieclip, and explan all the steps.

    Monday, November 8, 2010 at 7:53 pm #
  38. Amos wrote:

    Hi, Thibault,

    Nice work; thanks for sharing it!

    Just a couple of quick questions:

    1) Could you post the AS3 code from the .fla file separately? I’m using the Flex SDK and FlashDevelop, so I can’t open .fla files.

    2) Is what Iain said about not working in the browser correct?

    3) If so, is there any way to modify this solution to work in the browser?

    Thanks!

    Tuesday, March 1, 2011 at 12:48 pm #
  39. Terry wrote:

    Salut Thibault!
    Very cool, but only under XP. On Vista I can’t get it to work. Any ideas?

    Many thanks,
    Terry

    Tuesday, April 26, 2011 at 4:31 pm #
  40. The problem is sandBox type for the Player.
    for bypass this:
    Go to:C:\Documents and Settings\User\Application Data\Macromedia\Flash Player\#Security\FlashPlayerTrust
    with text editor: make a text file named with program name and .cfg attribut. For me is TestFlashStick.cfg.
    in the file add one line, way access.
    for me is : E:\Mes Animations\Etudes base\Joystick\FlashStick v0.31
    for verify this:
    add in your program: import flash.system.Security;
    add trace “sandBox Type: ” + Security.sandboxType
    the good result is localTrusted not localWithNetwork
    and enjoy the Message “Yay !! Connected”
    Merci Monsieur Thibault Imbert

    Thursday, August 14, 2014 at 11:18 am #

Trackbacks/Pingbacks (8)

  1. Tom’s Graphic Design Journal » The Power of Actionscript 3 on Saturday, April 28, 2007 at 9:03 pm

    [...] 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. [...]

     
  2. psibaspace » XBOX 360 Controllers in Adobe Flash on Saturday, October 11, 2008 at 6:17 am

    [...] to Thibault Imbert from ByteArray.org I was inspired to use the new binary sockets feature of Flash Actionscript 3 [...]

     
  3. Flash sprengt seine (Interaktions-) Grenzen | der hess on Thursday, April 30, 2009 at 4:36 pm

    [...] er diese Kommunikation erfolgreich entwickelte, könnt ihr auch in diese Fall wieder in seinem Blog [...]

     
  4. analog joystick - StartTags.com on Monday, January 25, 2010 at 12:39 am

    [...] 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 [...]

     
  5. Joystick -> Force Feedback -> irgendwie? - Flashforum on Monday, June 14, 2010 at 4:31 pm

    [...] [...]

     
  6. Game Controllers in AIR 2.0 - ByteArray.org on Wednesday, August 11, 2010 at 6:31 pm

    [...] game controllers to the Flash Player is something I experimented in the past with FlashStick and a few years ago with WiiFlash with Joa. One of the limitations with those implementations is [...]

     
  7. Flash with joystick(i-too) connection – FYP Blog @周英P on Friday, September 24, 2010 at 12:34 pm

    [...] http://www.bytearray.org/?p=64 [...]

     
  8. 好久前的笑話! | 北七老頭的家庭聯絡簿 on Tuesday, June 25, 2013 at 9:39 pm

    [...] http://www.bytearray.org/?p=64 [...]