Klye
Klye

Reputation: 104

AS3: Drawing Lines With Touch Screens

,Hey guy's I am kind of a newbie with AS3 and there touch events, for touch screens. So what I am trying to look to do is draw a line behind where ever the user is dragging his/her finger, then on release clear the line. I am also hoping to do multi-touch so the user can use multiple fingers, not to sure if that's possible with AS3 though. Thanks for the help everyone! Currently working off of this

import flash.ui.Multitouch;
import flash.ui.MultitouchInputMode;
import flash.events.TransformGestureEvent;
import flash.events.MouseEvent;

Multitouch.inputMode = MultitouchInputMode.GESTURE;

var lineContainer:Shape = new Shape();

square_mc.addEventListener(TransformGestureEvent.GESTURE_PAN, onPan);
square_mc.addEventListener(TransformGestureEvent.GESTURE_ROTATE, onRotate);
square_mc.addEventListener(TransformGestureEvent.GESTURE_ZOOM, onZoom);
stage.addEventListener(MouseEvent.MOUSE_DOWN, drawlines);

square_mc.gotoAndStop(1);

function onPan (e:TransformGestureEvent):void{
    square_mc.y += e.offsetY;
    square_mc.x += e.offsetX;
    square_mc.gotoAndStop(3);
}

function onRotate (e:TransformGestureEvent):void{
    square_mc.rotation += e.rotation;
    square_mc.gotoAndStop(2);
}

function onZoom (e:TransformGestureEvent):void{
    square_mc.scaleX *= e.scaleX;
    square_mc.scaleY *= e.scaleY;
    square_mc.gotoAndStop(4);
}

function drawlines(e:MouseEvent):void {
            lineContainer.graphics.clear(); 
            lineContainer.graphics.lineStyle(5, 0x0099FF); 
            lineContainer.graphics.endFill();
}

Upvotes: 0

Views: 509

Answers (1)

VC.One
VC.One

Reputation: 15926

Mouse events do work in touchscreens. Example a left mouse-click becomes a "tap". Best put

trace ("I am Mouse Click.. working!!")

as first line inside that function drawlines(e:MouseEvent):void if you get that trace message then the code is working fine.

Also you won't see anything with your code cos even though you got var lineContainer:Shape = new Shape(); you did not then later add that shape to the display with addChild (lineContainer); So Flash knows what you mean but you havent told it to show you what's happening.

Final advice is best make a container Sprite also for the LineContainer. The Sprite has the ability to listen for Mouse events just like the Stage. If you called this Sprite "canvas" then
canvas.addEventListener(MouseEvent.MOUSE_DOWN, drawlines);

Upvotes: 1

Related Questions