Hey guys ive been trying to implement touch inputs to a flash app i have. it hasnt been going to well. Mainly because its the touch inputs arent working.... anyway here is
a bit of code maybe someone could point me out to how to fix it. Provide me the code to implement touch inputs.
public function ParticleStream (container:DisplayObjectContainer, width:int = 800, height:int = 600)
{
this.container = container;
stage = container.stage;
canvasWidth = width;
canvasHeight = height;
initStage();
initLines();
initBitmap();
setFullScreenQuality();
}
/**
* Sets up stage listeners
*/
private function initStage():void
{
stage.scaleMode = StageScaleMode.NO_SCALE;
stage.addEventListener(Event.RESIZE, stageResizeListener);
//stage.addEventListener(Event.MOUSE_LEAVE, mouseLeaveListener);
stage.addEventListener(TouchEvent.MOUSE_MOVE, tuioMoveListener);
stage.addEventListener(TouchEvent.MOUSE_DOWN, tuioDownListener);
stage.addEventListener(TouchEvent.MOUSE_UP, tuioUpListener);
stage.addEventListener(MouseEvent.MOUSE_MOVE, mouseMoveListener);
stage.addEventListener(MouseEvent.MOUSE_DOWN, mouseDownListener);
stage.addEventListener(MouseEvent.MOUSE_UP, mouseUpListener);
stage.addEventListener(FullScreenEvent.FULL_SCREEN, setFullScreenQuality);
stage.addEventListener(Event.ENTER_FRAME, update);
}
/**
* Sets up line variables
*/
************************************************************************************
************************************************************************************
private function tuioMoveListener(e:TouchEvent)
{
var tuioobj:TUIOObject = TUIO.getObjectById(e.ID);
var localPt:Point = parent.globalToLocal(new Point(tuioobj.x, tuioobj.y));
}
private function mouseMoveListener(e:MouseEvent):void
{
//paused = false;
}
/**
* Listens for mouse or touch press
*/
private function tuioDownListener(e:TouchEvent)
{
var tuioobj:TUIOObject = TUIO.getObjectById(e.ID);
var localPt:Point = parent.globalToLocal(new Point(tuioobj.x, tuioobj.y));
//localPt.x, localPt.y
}
private function mouseDownListener(e:MouseEvent):void
{
// Allow a kind of drawing-mode when mouse is pressed
spread = SPREAD_MIN;
}
/**
* Listens for mouse or touch press
*/
private function tuioUpListener(e:TouchEvent)
{
var tuioobj:TUIOObject = TUIO.getObjectById(e.ID);
var localPt:Point = parent.globalToLocal(new Point(tuioobj.x, tuioobj.y));
}
private function mouseUpListener(e:MouseEvent):void
{
// Spread lines out when mouse is released
spread = SPREAD_MAX;
}
*************************************************************************************
*************************************************************************************
private function update(e:Event):void
{
//if (paused) return;
// Line movement is set by how much the mouse has moved since its previous position and a random value
var dx:Number = (container.mouseX - px + Math.random() * 4 - 2) / 2;
var dy:Number = (container.mouseY - py + Math.random() * 4 - 2) / 2;
// Limit the amount of movement
if (dx < -spread) dx = -spread;
if (dx > spread) dx = spread;
if (dy < -spread) dy = -spread;
if (dy > spread) dy = spread;
// Store the mouse position
px = container.mouseX;
py = container.mouseY;
// Line thickness varies up and down with sine
var s:Number = Math.sin(size += 0.2) * 8 + 4;
// Put the red, green and blue values together into a single hexadecimal value
var c:uint = (Math.sin(red += RED_STEP) * 128 + 127) << 16 | (Math.sin(green += GREEN_STEP) * 128 + 127) << 8 | (Math.sin(blue += BLUE_STEP) * 128 + 127);
// Create a new point on the line
list.push(new particlePoint(px, py, dx, dy, s, c));
// Draw!
drawLines();
drawBitmap();
}
well as you can see all my mouse events do is detect if the left mouse button has been pressed or not and change the spread/thickness of the drawlines function. in Update i have my actual work being done, where is checks for the location of the mouse and draws accordingly. my main problem is i am unable to change this part so it works the way its working with the mouse.
any help would be apprecaited.
NOTE: any by the way i know my touch inputs dont do anything at the moment either.... what i am more worried about is how to get my touch events to draw first and then i plan to work on the spread.
thanks in advance for the help
Taha
