Introducing the MultiDraggable Touch API

Updates: I changed the name of the post as technically this is not a gesture API. It is a way to achieve gesture-like effects using touch data. Also the code below was missing an important line. You have to set the input mode to touch point in order for any of this to work.

As part of my multi-touch session at Flashbelt I introduced a new API for getting true multi-touch gestures in Flash. Windows 7 has a pretty big limitation when it comes to gestures as it is only capable of doing one at a time. Since Flash listens for these native events, we also get that limitation when doing multi-touch in Flash.

Tim Kukulski, who is a member of the Adobe XD team, has written a great set of classes that listens for raw touch events instead of the built-in gestures. The main class, called MultiDraggable, does all of the work for you and allows you to quickly add zoom, rotate, and drag gesture effects to any DisplayObject. See the video below for an example.

The code needed to implement the gesture effects is extremely simple. Below is a code snippet of how to do it. You simply add your DisplayObject to the display list of a MultiDraggable instance. Then add the MultiDraggable instance to the main display list.

1
2
3
4
5
6
7
8
9
10
import xd.parts.MultiDraggable;

Multitouch.inputMode = MultitouchInputMode.TOUCH_POINT;

// box is a MovieClip in the library
var b:MovieClip = new box();

var dragme:MultiDraggable = new MultiDraggable();
dragme.addChild(b);
addChild(dragme);

Big thanks to Tim for releasing this code. Photos and artwork in the video are from Ralph and Mario. Go ahead and download the files and have fun spawning multiple gestures!


Commentary

  1. Andy says:

    wow.. this is great! very smooth and no sluggish at all.

  2. nicowakeup says:

    YESSSS!!! go flashh!!!

  3. mic says:

    This is awesome!! Looking forward to playing with it!

  4. BoteRock says:

    nice =) so sad in wont work on macbook trackpad =(

  5. Seth says:

    Thanks for the post and sharing Lee!

    I’m hoping to see the API developed further in the future. :D

  6. Dheavy says:

    Exactly what I needed, and I’m certainly not the only one.
    Thank you guys!

  7. Ocho Durando says:

    Fantastic!
    Can I use MultiDraggable Gestures on MacBook Pro trackpad?

    Ocho

  8. Dimitree says:

    For whom the bells tool…

  9. Lawrie says:

    Wow….I can’t believe Microsoft were happy with that – that first video is painful to watch even for just a few seconds. Great job to Tim for making the second demo amazing.

  10. Elliot Rock says:

    Nice stuff Tim. thnaks for the post lee.

  11. Yeay for Flash! Yeay for Multi-Touch! Yeay for Metallica!

  12. Og2t says:

    Nice! I am looking for Flash Player 10.1 Standalone for Mac to test it (currently only work with AIR). There’s also another open-source project that seems to support multi draggable gestures – haven’t tested it yet though, but it looks interesting.

    http://gestureworks.com/about/open-source-gesture-library/

  13. Clint says:

    Very nice!

    This class bypass the Windows 7 OS limitations, but will it also bypass hardware limitations (ie: touch screens / devices) that only allow one touch point?

    Thanks Lee, go Team Adobe!

  14. This is brilliant! Thank you for sharing this. =)

  15. Farid says:

    Woohoo! Awesome! Is it optimized only for Windows 7 or it’s that smooth on other platform such as android and … !?

  16. Kribba says:

    Looks sweet, hope I can implement at my touchscreen company soon.

    Wish to never ever see that pic with you and the meatball again ;)

  17. Min Thu says:

    This is really awesome!

  18. karlus says:

    smooooooth :D nice choice for bg music.

  19. greg says:

    yeah!! I can’t believe that MS built in such limitation into the native multitouch supportof win 7. this is the prerequisite for real multi-user input on big devices like tabletops! Thanks a lot for sharing this..

  20. jloa says:

    That was HUGE!!!
    And the sound track you’ve picked up hahaha
    You get an A for this one ;)

  21. David says:

    Thanks for sharing. And thank Tim – I was just researching to see if anyone had done an custom gesture gesture api yet. Glad to see you guys have got the ball rolling.

  22. Don Kerr says:

    Excellent! Thanks Tim and Lee! Much needed. The native gestures of Air 2 were a bit sluggish and they didn’t support true multi-user, multi-touch.

    Great stuff!
    Don Kerr
    Manager, Space City Adobe User Group
    http://www.spacecityaug.com

  23. Norm says:

    Looks really nice! I have a multi-touch monitor on the way that I’m excited about. Seems odd though that the built-in multi-touch events in Windows 7 are so horrible. I have never used any of it, but I have extensive experience with Microsoft Surface and those multi-touch events are absolutely great, and that was back before Windows 7 even came out.

  24. Steve says:

    Lee – Can you do a little write up on best practices (or maybe capabilities) for testing multitouch. I develop on both a PC and a Mac and I realize that to date, it seems that multitouch devices fit into one of these categories…

    1. Mobile devices: Android OS, iOS.
    2. Windows 7 systems.

    What I am curious about is if there might be a workflow for adding a component like…

    - Wacom bamboo touch –
    http://www.wacom.com/bamboo/bamboo_touch.php

    … and will flash respond to raw multitouch data from that type of device so one could test their efforts on a mac or pc?

  25. Ollie Olarte says:

    WHY!!! the best multitouch screen is SOO DAMN expensive!! :P
    Lee: what do you think about dell’s multitouch display:

    SX2210T in relation to flash player new multitouch capabilities

    OR: what should I look for in order to choose a good multi touch display

    in relaltion with the reaction speed, touch point etc?!

    http://accessories.us.dell.com/sna/products/Displays/productdetail.aspx?c=us&l=en&cs=19&sku=320-1172

  26. jt says:

    Very nice.

    Can this be tested using Device Central’s multitouch emulator?

  27. al says:

    Where do you get: flash.events.TouchEvent

    I can’t compile without it and you make no mention of it…

  28. jt says:

    I tried testing this through Device Central and it does seem to work except that after a handful of interactions I get this error.

    TypeError: Error #1009: Cannot access a property or method of a null object reference.
    at xd.touch::MultiTouchTracker/dispatch()
    at xd.touch::MultiTouchTracker/touchEnd()

    Also, I couldn’t get this to work simply using the code you site in your post. I also had to use one of the classes in the “touch” package. So after line 6 in your code I added:

    import xd.touch.GestureRecognizer;

    var gestureRecognizer:GestureRecognizer = new GestureRecognizer(dragme);

    Any plans to document this API or do a more thorough tutorial?

  29. Aaron says:

    Don’t mean to be bashing Microsoft (*looks around for Silverlight fans*), but I didn’t realize their Win 7 gesture support was so bad! Especially compared to how good and somewhat ground breaking Microsoft Surface was. I just got a Win 7 machine, I sincerely hope they release an update which improves gesture support, I’d hate to have to wait for the next Windows OS to get multiple gestures at once natively.

    Nice info, thanks for the post!

  30. Allan says:

    This looks great. A big improvement. Now all I need is a touch screen :)

  31. lee says:

    @jt I updated the code in my post. Sorry I left out an important line.

  32. Flo says:

    Hi,

    Does someone noticed the issue with TouchEvent.stageX or stageY when touching an FLV file ? It’s like touch points are following a kind of grid.

  33. Flo says:

    Here’s an illustration of what I wrote just before:
    http://dl.dropbox.com/u/1056083/drawing.jpg

    The red line comes from a TouchEvent.
    As you can see on an FLV, the point follows a grid, when there’s no problem when drawing on (or touching) something else.

    Does anyone knows?

  34. lee says:

    @Flo wow that is really strange. Let me try to find out what is happening. What if you draw on a MovieClip that contains an FLV? Same thing?

  35. personman says:

    Could you put a few more palm mutes into the music there?

  36. Donovan Douglas says:

    Wow! Great Job. It is amazing you can get passed a Windows limitation like this with so little code.

  37. Wow, really great!!!

    One question… is there a simple way to limit the scale of the Movieclip / Bitmap ?

    I have a big image 2500×800 I wil like to limit his dimensions to 4095×4095. If the dimensions get bigger the image is hidden. Flash limits of image dimensions is the problem… I imagine.

  38. Marcus says:

    Slightly off topic but I think if Cliff Burton wouldn’t have died he either would have left the band because the rest of them became such douche bags or maybe his sheer presence would have kept them from becoming one.. just my 2 cent.. anyways – this is the best version /watch?v=rTz0xQomNFg :)

  39. Flo says:

    @lee yep that’s really strange as you said. The Video instance is embedded in a MovieClip. Same thing.

  40. Thanks for the post Lee, and thanks for the code Time.

  41. Clayton says:

    Awesome, this works on my Droid. Waaaay easy!

  42. Radu says:

    Will it work on Android phones ?

  43. hp says:

    Hi

    how can I drag without leaving the stage?

    tks

  44. Clayton says:

    It does work on android phones, tested here!

  45. Gameonade says:

    That is really really awesome. I didn’t know that this is even possible.

  46. Phil says:

    Does anyone know which hardware this is running on? we have a huge project for touchscreens and the devices we were given are crap, we need to give them a hardware example that can truly show off flash multitouch,
    thanks

  47. Ben Faubion says:

    Nice quick implementation. Thanks! I tried the Gestureworks library, it’s nice.. but this one is just so easy and less complicated.. plus it’s free.

Leave a Comment