-- Perhaps Too Simple

I was looking through all the TUIO files when I came across something interesting. In TouchEvents.as, there is a variable called 'relatedObject,' what did that mean I thought. So I opened up a new file and figured out how to run a trace on it. Low and behold, relatedObject will return whatever object it is touching. I knew this also when I touched the screen and the normal full sized black square I put on my files immediately followed my touch.

2 Lines of code! dragging accomplished, what?! Well, a little more than 2 lines (^_^), you need all the other code to hook in TUIO and add an event listener. So i tried putting just a bunch of random movie clips (not just shapes because they would be all created on the same level) on the stage. Each MovieClip could be moved independently, it's activated when the touch point moves and it'll snap the MovieClip's anchor point to the center of the touch point, but it's not without its issues. A few times when i dragged a MovieClip over another movie clip it'll connect to the one at the highest level. But it was something I stumbled across I though was worth sharing.

Name your AS file: SimpleDrag.as
Put into this folder structure: app/demo/MyTouchApp
In flash, set your Document Class to: app.demo.MyTouchApp.SimpleDrag

  1. package app.demo.MyTouchApp{
  2.  
  3. import flash.events.TUIO;// allows to connect to touchlib/tbeta
  4. import flash.events.TouchEvent;// allows to use TouchEvent Event Listeners
  5. import flash.display.*;
  6.  
  7. public class SimpleDrag extends Sprite {
  8.  
  9. public function SimpleDrag():void {
  10. //--------connect to TUIO-----------------
  11. TUIO.init(this,'127.0.0.1',3000,'',true);
  12. addEventListener(TouchEvent.MOUSE_MOVE, moveUpdate);//run moveUpdate, when any touching point is moved
  13.  
  14. }
  15. public function moveUpdate(e:TouchEvent):void {
  16. trace("moved: "+e.ID+" related to: "+e.relatedObject.name);
  17. e.relatedObject.x = e.localX;
  18. e.relatedObject.y = e.localY;
  19. }
  20. }
  21. }

Updated in my Google Code SVN page as well.

Happy Experimenting.