Only 1 touch working, multi touch didn’t. Need Help :’(
Posted: 23 July 2013 02:30 AM   [ Ignore ]
Avatar
Rank
Joined  2013-02-08
Total Posts:  25
New Member

Hi everybody…
I try to build a simple application for my multitouch project. I modified from demo example on as3 library PaintCanvas.
I removed the blur effect and I got the solid line. When I touch with 1 finger (1 blob detected) it’s working fine, but when I try to adding the touch, the stage is make a line from blob 1 current position to another blob position… and the color transform didn’t working too.. can anybody tell me what’s going on? :’(
I attach a pic how my code work strangely with tuio simulator
Here’s my code :

package app.core
{
    import flash
.display.Bitmap;
    
import flash.display.BitmapData;
    
import flash.display.*;        
    
import flash.events.*;
    
import flash.net.*;
    
import flash.events.*;    
    
import flash.geom.*;        
    
import app.core.Wrapper;
   
    public class 
PaintCanvas extends Sprite
    {
        
private var blobs:Array;        // blobs we are currently interacting with
        
private var m_stage:Stage;        
        private var 
paintBmpData:BitmapData;    
        private var 
paintBmp:Bitmap;
        private var 
brush:Sprite;
        private var 
col:ColorTransform;
        private var 
colorBar_0:Sprite;
        private var 
colorButton_0:Sprite;
        private var 
colorButton_1:Sprite;        
        private var 
colorButton_2:Sprite;        
        private var 
colorButton_3:Sprite;
        private var 
colorButton_4:Sprite;        
        private var 
colorButton_5:Sprite;        
        private var 
colorButton_6:Sprite;        
        
        private var 
bInit:Boolean false;
        
        public function 
PaintCanvas():void
        {
            this
.addEventListener(Event.ADDED_TO_STAGEthis.addedToStagefalse0true);                    
        
}
        
        
function addedToStage(e:Event)
        
{
            m_stage 
this.stage;
            if(
bInit)
                return;
        
            
blobs = new Array();
            
paintBmpData = new BitmapData(m_stage.stageWidthm_stage.stageHeighttrue0x00000000);
                
            
this.addEventListener(TouchEvent.MOUSE_DOWNthis.downEventfalse0true);                        
            
this.addEventListener(TouchEvent.MOUSE_UPthis.upEventfalse0true);    
            
             var 
colorBar_0:Sprite = new Sprite();
                     
             
colorBar_0.graphics.beginFill(0xFFFFFF,0.65);
             
colorBar_0.graphics.drawRoundRect(00m_stage.stageWidth6010);
             
colorBar_0.0;    
             
colorBar_0.m_stage.stageHeight-70;    
                
             var 
colorButton_0:Sprite = new Sprite();
             var 
colorButton_1:Sprite = new Sprite();        
             var 
colorButton_2:Sprite = new Sprite();    
             var 
colorButton_3:Sprite = new Sprite();
             var 
colorButton_4:Sprite = new Sprite();        
             var 
colorButton_5:Sprite = new Sprite();    
             var 
colorButton_6:Sprite = new Sprite();    
              
            
colorButton_0.graphics.beginFill(0xFFFFFF);
            
colorButton_0.graphics.drawRoundRect(007050,6);            
            
colorButton_0.5;
            
colorButton_0.10;    
            
            
colorButton_1.graphics.beginFill(0xFF0000);
            
colorButton_1.graphics.drawRoundRect(007050,6);    
            
colorButton_1.5;                    
            
colorButton_1.90;    
                
            
colorButton_2.graphics.beginFill(0xFFFFFF);
            
colorButton_2.graphics.drawRoundRect(007050,6);                                    
            
colorButton_2.5;    
            
colorButton_2.170;    
            
            
colorButton_3.graphics.beginFill(0x00FF00);
            
colorButton_3.graphics.drawRoundRect(007050,6);            
            
colorButton_3.5;    
            
colorButton_3.250;
            
            
colorButton_4.graphics.beginFill(0x0000FF);
            
colorButton_4.graphics.drawRoundRect(007050,6);    
            
colorButton_4.5;                    
            
colorButton_4.330;
            
            
colorButton_5.graphics.beginFill(0xFFFF00);
            
colorButton_5.graphics.drawRoundRect(007050,6);                                    
            
colorButton_5.5;    
            
colorButton_5.410;
            
            
colorButton_6.graphics.beginFill(0x000000);
            
colorButton_6.graphics.drawRoundRect(007050,6);            
            
colorButton_6.5;    
            
colorButton_6.490;
            
             var 
colorWrapper_0:Wrapper = new Wrapper(colorButton_0);
             var 
colorWrapper_1:Wrapper = new Wrapper(colorButton_1);
             var 
colorWrapper_2:Wrapper = new Wrapper(colorButton_2);
             var 
colorWrapper_3:Wrapper = new Wrapper(colorButton_3);
             var 
colorWrapper_4:Wrapper = new Wrapper(colorButton_4);
             var 
colorWrapper_5:Wrapper = new Wrapper(colorButton_5);
             var 
colorWrapper_6:Wrapper = new Wrapper(colorButton_6);
             
            
colorWrapper_0.addEventListener(MouseEvent.CLICK, function(){trace("DOWN");setColor(0.00.00.0);}false0true);                                    
            
colorWrapper_1.addEventListener(MouseEvent.CLICK, function(){trace("DOWN");setColor(1.00.00.0);}false0true);    
            
colorWrapper_2.addEventListener(MouseEvent.CLICK, function(){trace("DOWN");setColor(1.01.01.0);}false0true);                                    
            
colorWrapper_3.addEventListener(MouseEvent.CLICK, function(){trace("DOWN");setColor(0.01.00.0);}false0true);
            
colorWrapper_4.addEventListener(MouseEvent.CLICK, function(){trace("DOWN");setColor(0.00.01.0);}false0true);                                    
            
colorWrapper_5.addEventListener(MouseEvent.CLICK, function(){trace("DOWN");setColor(1.01.00.0);}false0true);
            
colorWrapper_6.addEventListener(MouseEvent.CLICK, function(){trace("DOWN");setColor(1.01.01.0);}false0true);
    
            
paintBmp = new Bitmap (paintBmpData);
            
            
addChild(paintBmp);                    

            
colorBar_0.addChild(colorWrapper_0);
            
colorBar_0.addChild(colorWrapper_1);
            
colorBar_0.addChild(colorWrapper_2);
            
colorBar_0.addChild(colorWrapper_3);
            
colorBar_0.addChild(colorWrapper_4);
            
colorBar_0.addChild(colorWrapper_5);
            
colorBar_0.addChild(colorWrapper_6);
                
            
this.addChild(colorBar_0);

            
setColor(1.01.01.0);

            
bInit true;
        
}
        
        
function setColor(r:Numberg:Numberb:Number):void
        {
            col 
= new ColorTransform(rgb);
        
}
        
        
function addBlob(id:NumberorigX:NumberorigY:Number):void
        {
            
for(var i=0i<blobs.lengthi++)
            
{
                
if(blobs[i].id == id)
                    return;
            
}

            blobs
.push{ ididorigXorigXorigYorigYmyOrigXxmyOrigY:y } );

        
}
        
        
function removeBlob(id:Number):void
        {
            
for(var i=0i<blobs.lengthi++)
            
{
                
if(blobs[i].id == id
                
{
                    blobs
.splice(i1);        
                    return;
                
}
            }
        }
        
        
public function downEvent(e:TouchEvent):void
        {        
            
if(e.stageX == && e.stageY == 0)
                return;    
            var 
curPt:Point parent.globalToLocal(new Point(e.stageXe.stageY));    
            
addBlob(e.IDcurPt.xcurPt.y);
            
            for(var 
i:int 0i<blobs.lengthi++)
            
{
                
var tuioobj:TUIOObject TUIO.getObjectById(blobs[i].id);
                
trace("ID : " blobs[i].id);
                
trace(blobs[i].origX "," curPt.x);
                
trace(blobs[i].origY "," curPt.y);
                
                
                
graphics.lineStyle(30xffffff);
                var 
localPt:Point parent.globalToLocal(new Point(tuioobj.xtuioobj.y));                                        
                var 
m:Matrix = new Matrix();
                
m.translate(localPt.xlocalPt.y);
                
graphics.moveTo(localPt.xlocalPt.y);
                
this.addEventListener(TouchEvent.MOUSE_MOVEmoveHandler);
                
e.stopPropagation();
            
}
        }
        
        
public function upEvent(e:TouchEvent):void
        {        
            removeBlob
(e.ID);            
                
            
e.stopPropagation();                
                
        
}    
        
        
public function moveHandler(e:TouchEvent):void
        {
                
var curPt:Point parent.globalToLocal(new Point(e.stageXe.stageY));
                if (
e.stageY == curPt.&& e.stageY == curPt.y)
                    return;
                else
                
{
                    graphics
.lineTo(e.stageXe.stageY);
                
}
                
        }    
        
    }
}

Profile