— 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

package app.demo.MyTouchApp{

	import flash.events.TUIO;// allows to connect to touchlib/tbeta
	import flash.events.TouchEvent;// allows to use TouchEvent Event Listeners
	import flash.display.*;

	public class SimpleDrag extends Sprite {

		public function SimpleDrag():void {
			//--------connect to TUIO-----------------
			addEventListener(TouchEvent.MOUSE_MOVE, moveUpdate);//run moveUpdate, when any touching point is moved

		public function moveUpdate(e:TouchEvent):void {
			trace("moved: "+e.ID+" related to: "+e.relatedObject.name);
			e.relatedObject.x = e.localX;
			e.relatedObject.y = e.localY;

Updated in my Google Code SVN page as well.

Happy Experimenting.