• Tutorials
  • Blog
  • About
  • Contact
  • SimTouch – Simulate Native TouchEvents on the Flash Platform

    2010 - 03.01

    sim_touch_logo_128So, I promised SimTouch would be good to go by March 1st and here it is in all it’s ‘beta’ glory.  SimTouch is an Adobe Air application that simulates native touch events on the Flash platform.  SimTouch is a transparent app that sits on top of the application that you are developing and dispatches TouchEvents to your application through a connection class over sockets.  Additionally, by using the SimConnect class you can use your iPhone to simulate Touch Events.  Be sure to check out this video for an over view of what SimTouch is and how it functions.

    You’ll need to download the SimConnection swc:

    SimConnect.swc

    That’s all you’ll need to use the iPhone simulator but if you’d like to use the SimTouch Air app you’ll need this:

    SimTouch.air (Air 2.0 required)

    Currently SimTouch only dispatches TOUCH_BEGIN, TOUCH_MOVE, and TOUCH_END events.

    The SimTouch application works by sending data over sockets.  You can either send data over up sockets using a custom binary protocol or you can send touch data over tcp sockets using an XML protocol.  Both perform well and I haven’t detected too much improvement using UDP.  However UDP is required to use the iPhone connection method.

    To use the SimConnect swc with the flex framework, simply download the swc and drop it in you ‘libs’ folder of you new application.  To start the connection class simply pass the stage to a new SimConnection class.    ex:

    <s:WindowedApplication xmlns:fx=”http://ns.adobe.com/mxml/2009″
    xmlns:s=”library://ns.adobe.com/flex/spark”
    xmlns:mx=”library://ns.adobe.com/flex/halo”
    applicationComplete=”applicationCompleteHandler(event)”
    width=”1024″ height=”768″>

    <fx:Script>
    <![CDATA[
    import com.multitouchup.simConnect.SimConnection;
    import mx.events.FlexEvent;

    protected function applicationCompleteHandler(event:FlexEvent):void
    {
    var s:SimConnection = new SimConnection(this.stage, 3333, "127.0.0.1", debugCan, false, false);
    }
    ]]>
    </fx:Script>
    <mx:Canvas id=”debugCan” width=”100%” height=”100%” />
    </s:WindowedApplication>

    The preceding example shows a the start of the SimConnection class and passes in the stage, port, socket connection location, a debug canvas and sets udp to false and gestures to false.

    Gestures

    Currently the SimConnection class doesn’t dispatch gestures.   I do intend to build out that functionality someday.

    Connection to the iPhone

    The software that I am currently using to connect to SimConnect is called MSA Remote (iTunes link) by Memo.  It uses a custom UDP protocol to send Touch messages.  In order to connect to the iPhone one could use the previous code but set the socket location to the location of the current computer on the network and turn UDP to true.

    Here’s a quick video:
    SimTouch

    Why is my application all jittery?

    You may run into a bug in the Adobe Flex framework where when your application looses focus the framerate is dropped to 1 frame per second.  This is a known bug (SDK-25126) and is working correctly as of Flex 4 revision 14001.  I suggest going to opensource.adobe.com and pull a more resent version of the Flex SDK where they have this issue fixed. 1

    Using the TUIO protocol?

    If you are interested in using this application with TouchLib and the TUIO protocol please use the older version of this application.  At some point I’ll try to add an additional settings option for the folks that are interested in building apps with this library.  If you are using the old SimTouch, remember that you’ll need an additional socket server to connect with.

    **Update SimTouch should be started first.  Secondly, launch your application and it should connect to SimTouch.  The Socket Server needs to be running before the application can connect to it.  (Thanks Rodion Bykov!)

    **Update 2 To simulate gestures on a mac (not raw touch events) from the iPhone, skip SimConnect and go directly to this blog post “Touch Gestures with Adobe Flex, Adobe Air, and the iPhone” Do not pass go and do not collect 200 doll hairs. The iPhone application that sends gestures is called iTap.

    13 Responses to “SimTouch – Simulate Native TouchEvents on the Flash Platform”

    1. [...] Multitouch ile internete daha fazla dokunmak: Çeşitli hareket tanımları (gestures) sayesinde AIR geliştiricileri mobil uygulamalarında birden çok dokunuşun etkileşimini daha kolay uygulamalarına katabilecekler [Örnek] [...]

    2. Rodion Bykov says:

      Thanks, worked like a charm ! Note about Flex SDK build was very helpful also.

      Quick note – SimTouch should be run first and be running, and then sample application built/run in Flex Builder. Othervise apps don’t see each other and even ‘Reconnect’ button not helps.

    3. ebaggg says:

      Not sure why, but I’m getting this error when I first click the SIM overlay on my app (I do see in my debug console that it connects OK). I tried registering my TouchEvent listeners to the main app and the debucan, but get the same error for both.

      TypeError: Error #1009: Cannot access a property or method of a null object reference.
      at com.multitouchup.simConnect.xmlParser::XmlParser/getUpdateValues()[/Volumes/Tera/Users/mlegrand/Sites/multiTouchup/MultiTouchup Projects/SimConnect/src/com/multitouchup/simConnect/xmlParser/XmlParser.as:148]
      at com.multitouchup.simConnect.xmlParser::XmlParser/processString()[/Volumes/Tera/Users/mlegrand/Sites/multiTouchup/MultiTouchup Projects/SimConnect/src/com/multitouchup/simConnect/xmlParser/XmlParser.as:104]
      at com.multitouchup.simConnect.xmlParser::XmlParser/socketProgressEventHandler()[/Volumes/Tera/Users/mlegrand/Sites/multiTouchup/MultiTouchup Projects/SimConnect/src/com/multitouchup/simConnect/xmlParser/XmlParser.as:81]

    4. admin says:

      @ebagg,

      Thanks for pointing this out. The issue is due to the SimConnect class being passed a null stage object. I’ll add some sort of test for this. The ultimate solution is to instantiate the SimConnect class on the ApplicatonCompleteEvent and not the CreationCompleteEvent.

      I’m guessing a lot of people will hit this issue so I’ll make a note of it in the actual blog post.

      Thanks again!

    5. John says:

      I get the error

      1046: Type was not found or was not a compile-time constant: Canvas.

      when compiling from Flash (like you appear to be doing in your screencast). I think Canvas is a Flex component. Can I not instantiate a new SimConnection from Flash alone?

    6. sasi says:

      1046: Type was not found or was not a compile-time constant: DatagramSocketDataEvent

      I am getting this error with the creation of instance of simConnect class inside the applicationCompleteHandler(event:FlexEvent). any solutions..

    7. admin says:

      Sounds like you might not be using Adobe Air 2.0. Did you lay the new Air 2 sdk over an existing sdk?

      Or it’s possible that Adobe may have made some changes in their API going from beta to beta 2.

      If you happen to make changes to the open source project let me know and we’ll correct it in a release build.

      Thanks,
      Matt

    8. sasi says:

      Yes I didn’t have the latest version of adobe AIR sdk. I overlayed the latest version of the sdk. Now I am not getting the DatagramSocketDataEvent compile time error.

      Thanks & Regards

      Sasi.

    9. [...] and Libraries’ you will find a section on multitouch simulators.  My open-source SimTouch application is mentioned which is pretty [...]

    10. Nik says:

      Hello. I have some problems using your tool.
      1. Can’t install SimTouch.air (Air 2.0 required) here on pagel. I have latest air 2 beta but since it not released yet it impossible to install (read on adobe forum).
      2. I get last version from here http://code.google.com/p/simtouch/downloads/list. I run socket server and air application and my aplication connected to this server. But what next? What events should I listen. Currentli I listen for TouchEvent but have no result.
      Thanks.

    11. Pablo says:

      Hi folks,

      I’ve been facing the same issue described by Nik, i´ve started everything just like mentioned above but i didn’t listen any event.

      Tks.

    12. David says:

      I have the same problem. that comment above
      1046: Type was not found or was not a compile-time constant: DatagramSocketDataEvent
      I am getting this error with the creation of instance of simConnect class inside the applicationCompleteHandler(event:FlexEvent).
      But I’m using the latest version of Adobe AIR 2.6.
      any solutions..
      I’m using flex 4
      Thanks for your help

    13. admin says:

      Keep in mind that DatagramSocketDataEvent ( UDP socket traffic ) isn’t supported in an Adobe Flex project. It’s only supported in an Adobe Air 2.0+ project. Also there is currently not support for UDP in any of the Adobe Air mobile projects.

      I’ll be trying to figure out a way around some of these issues as well as moving this project over to github.

    Your Reply