For wat ever reason, this application will only do what it should (draw a line to your finger and calculate the distance) if you touch it in the very top left of the screen.
I added the ability to use the mouse to check it and it works everywhere. Its not the table, as it shows me where I am touching, the program will just not work.
I tried to make it only put a circle where I touched, and it did the same thing. But an other application I made that does exactly that (put circle where touched), will do it everywhere.
Wy not this one?
package app.demo{
import flash.display.*;
import flash.events.*;
import flash.net.*;
import flash.geom.*;
import flash.text.TextField;
public class MouseDistance extends Sprite {
private var sprite1:Sprite;
private var textField:TextField;
public function MouseDistance() {
init();
//--------connect to TUIO-----------------
TUIO.init(this,'localhost',3000,'',true);
trace("MyTouchApp Initialized");
//----------------------------------------
}
private function init():void {
sprite1 = new Sprite();
addChild(sprite1);
sprite1.graphics.lineStyle(4,0xff0000,1);
sprite1.graphics.drawCircle(0,0,40);
sprite1.x = stage.stageWidth /2;
sprite1.y = stage.stageHeight /2;
textField = new TextField();
addChild(textField);
stage.addEventListener(MouseEvent.MOUSE_DOWN, onMouseDown);
addEventListener(TouchEvent.MOUSE_DOWN, touchDown);//run touchdown, when touched
}
public function touchDown(e:TouchEvent):void {
graphics.clear();
var curPt:Point = parent.globalToLocal(new Point(e.stageX, e.stageY));//convert touch points to x,y
graphics.lineStyle(4,0xff0000,1);
graphics.moveTo(stage.stageWidth /2, stage.stageHeight /2);
graphics.lineTo(curPt.x, curPt.y);
var dx:Number = sprite1.x - curPt.x;
var dy:Number = sprite1.y - curPt.y;
var dist:Number = Math.sqrt(dx * dx + dy *dy);
textField.text = dist.toString();
}
public function onMouseDown(event:MouseEvent):void {
graphics.clear();
graphics.lineStyle(4,0xff0000,1);
graphics.moveTo(stage.stageWidth /2, stage.stageHeight /2);
graphics.lineTo(mouseX, mouseY);
var dx:Number = sprite1.x - mouseX;
var dy:Number = sprite1.y - mouseY;
var dist:Number = Math.sqrt(dx * dx + dy *dy);
textField.text = dist.toString();
}
}
}
