Simple app only works in very top left - help
Posted: 22 July 2008 06:02 PM   [ Ignore ]
Jr. Member
RankRank
Total Posts:  129
Joined  2008-05-31

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.stage.stageWidth /2;
            
sprite1.stage.stageHeight /2;



            
textField = new TextField();
            
addChild(textField);
            
stage.addEventListener(MouseEvent.MOUSE_DOWNonMouseDown);
            
addEventListener(TouchEvent.MOUSE_DOWNtouchDown);//run touchdown, when touched
        
}
        
        
        
        
public function touchDown(e:TouchEvent):void {
            graphics
.clear();
            
            var 
curPt:Point parent.globalToLocal(new Point(e.stageXe.stageY));//convert touch points to x,y

            
            
graphics.lineStyle(4,0xff0000,1);
            
graphics.moveTo(stage.stageWidth /2stage.stageHeight /2);
            
            
            
            
graphics.lineTo(curPt.xcurPt.y);
            var 
dx:Number sprite1.curPt.x;
            var 
dy:Number sprite1.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 /2stage.stageHeight /2);
            
graphics.lineTo(mouseXmouseY);
            var 
dx:Number sprite1.mouseX;
            var 
dy:Number sprite1.mouseY;
            var 
dist:Number Math.sqrt(dx dx dy *dy);
            
textField.text dist.toString();
        
}
    }
}

Profile
 
 
Posted: 22 July 2008 06:58 PM   [ Ignore ]   [ # 1 ]
Administrator
Avatar
RankRankRankRank
Total Posts:  582
Joined  2008-02-12

Hi you should take a look at the Multitouchable class, and extend your class to this…

 Signature 

My MultiTouch Blog

Profile
 
 
Posted: 22 July 2008 07:09 PM   [ Ignore ]   [ # 2 ]
Jr. Member
RankRank
Total Posts:  129
Joined  2008-05-31

Thanks.

What do I need to import to use this?
import com.touchlib.* ? //note: does not work

Also… where are all of these, and where do I find documentation on them?

I wish there was a pdf I could read, that explained how and when to use all these funky guys.
Knowing AS3 seems to be less than half the battle.

Profile
 
 
Posted: 22 July 2008 07:18 PM   [ Ignore ]   [ # 3 ]
Jr. Member
RankRank
Total Posts:  129
Joined  2008-05-31

Found it
import app.core.action.Multitouchable;

Does the same thing.

Id still love to know what this is though so I can enter in the wiki about it.
Why are none of the classes in there?

Should I start putting them in?

Profile
 
 
Posted: 23 July 2008 02:51 AM   [ Ignore ]   [ # 4 ]
Administrator
Avatar
RankRankRankRank
Total Posts:  582
Joined  2008-02-12

Well basically this class allows you handle multiple blobs i.e. it makes the stage multitouchable, that may interact with a Sprite, such as touching and moving. Essentially it handles the touchevents. and when you extend this class you just need to implement the handler functions of the multitouchable class.

And btw you should check out the paint app, it will simplify your problems…

 Signature 

My MultiTouch Blog

Profile