Home Tutorials Forums Articles Blogs Movies Library Employment Press
Old 02-16-2012, 08:46 PM   #1
Bluepear_Design
Registered User
 
Join Date: Nov 2011
Posts: 8
Default [iOS] TouchEvent-dragline not working

I want to draw a line from the TOUCH_BEGIN anywhere on the screen then DRAG it out to TOUCH_END. Then it should disappear(which it does not). But he line isn't working! It keeps starting from the top left not where I put my finger!

Help really appreciated!



Code:
import flash.events.Event;
import flash.events.TouchEvent;
Multitouch.inputMode = MultitouchInputMode.TOUCH_POINT;
this.stage.addEventListener(TouchEvent.TOUCH_BEGIN, onTouchBegin );
this.stage.addEventListener(TouchEvent.TOUCH_MOVE, onTouchMove );
this.stage.addEventListener(TouchEvent.TOUCH_END, onTouchEnd );

var line:Sprite;
var xPos:int;
var yPos:int;
line = new Sprite();
addChild(line);

stage.addEventListener(TouchEvent.TOUCH_BEGIN, onTouchBegin);
stage.addEventListener(TouchEvent.TOUCH_END, onTouchEnd);
stage.addEventListener(Event.ENTER_FRAME, enterHandler);


function enterHandler(e:Event):void
{
	xPos = this.stageX;
	yPos = this.stageY;

}

function onTouchBegin(event:TouchEvent):void
{
	line.graphics.lineStyle(2);
	stage.addEventListener(TouchEvent.TOUCH_MOVE, onTouchMove);
	stage.removeEventListener(Event.ENTER_FRAME, enterHandler);

}
function onTouchEnd(event:TouchEvent):void
{
	line.graphics.clear();
	stage.removeEventListener(TouchEvent.TOUCH_MOVE, onTouchMove);
	stage.addEventListener(Event.ENTER_FRAME, enterHandler);
}
function onTouchMove(event:TouchEvent):void
{
	line.graphics.clear();
	line.graphics.moveTo(xPos,yPos);
	line.graphics.lineStyle(15);
	line.graphics.lineTo(event.stageX, event.stageY);
}
Bluepear_Design is offline   Reply With Quote
Old 02-17-2012, 12:04 AM   #2
peptobismol
Senior Member
 
Join Date: Oct 2005
Posts: 746
Default

Code:
function enterHandler(e:Event):void
{
	xPos = this.stageX;
	yPos = this.stageY;

}
always top left.
peptobismol is offline   Reply With Quote
Old 02-17-2012, 06:02 PM   #3
Bluepear_Design
Registered User
 
Join Date: Nov 2011
Posts: 8
Default

Thanks peptobismol.

I guessed it was that part of the code but because I'm new to touchevents I'm struggling to find the correct function.

... if I had this.mouseX & this.mouseY it would work (via a mouse) but for a touch events I'm stuck.

Thanks
Bluepear_Design is offline   Reply With Quote
Old 02-17-2012, 07:52 PM   #4
peptobismol
Senior Member
 
Join Date: Oct 2005
Posts: 746
Default

touch and mouseevents are basically the same thing. It's actually more efficient to use mouse events.
peptobismol is offline   Reply With Quote
Old 02-17-2012, 10:52 PM   #5
Bluepear_Design
Registered User
 
Join Date: Nov 2011
Posts: 8
Default

It works via Mouse events but not when I put it on the iPad!

Here's the code. It goes really weird on the iPad. Why?? Hence why I tried to change it to touch.


Code:

import flash.events.Event;

var line:Sprite;
var xPos:int;
var yPos:int;
line = new Sprite();
addChild(line);

stage.addEventListener(MouseEvent.MOUSE_DOWN,mouse DownHandler);
stage.addEventListener(MouseEvent.MOUSE_UP,mouseUp Handler);
stage.addEventListener(Event.ENTER_FRAME, enterHandler);


function enterHandler(e:Event):void{
xPos = this.mouseX;
yPos = this.mouseY;

}

function mouseDownHandler(event:MouseEvent):void {
line.graphics.lineStyle(2);
stage.addEventListener(MouseEvent.MOUSE_MOVE,movem ent);
stage.removeEventListener(Event.ENTER_FRAME, enterHandler);

}
function mouseUpHandler(event:MouseEvent):void {
line.graphics.clear();
stage.removeEventListener(MouseEvent.MOUSE_MOVE,mo vement);
stage.addEventListener(Event.ENTER_FRAME, enterHandler);
}
function movement(event:MouseEvent):void {
line.graphics.clear();
line.graphics.moveTo(xPos,yPos);
line.graphics.lineStyle(15);
line.graphics.lineTo(mouseX,mouseY);
}
Bluepear_Design is offline   Reply With Quote
Old 02-18-2012, 01:27 AM   #6
peptobismol
Senior Member
 
Join Date: Oct 2005
Posts: 746
Default

Code:
mouse DownHandler
no space
peptobismol is offline   Reply With Quote
Old 02-18-2012, 08:08 AM   #7
Bluepear_Design
Registered User
 
Join Date: Nov 2011
Posts: 8
Default It copied across badly doe some reason

Hi peptobismol

Sorry it copied across badly last night... did it quickly before I went out so I didn't check.

Here's the code again. Work a treat on my computer but not on the iPad!

Thanks again

Code:
import flash.events.Event;

var line:Sprite;
var xPos:int;
var yPos:int;
line = new Sprite();
addChild(line);

stage.addEventListener(MouseEvent.MOUSE_DOWN,mouseDownHandler);
stage.addEventListener(MouseEvent.MOUSE_UP,mouseUpHandler);
stage.addEventListener(Event.ENTER_FRAME, enterHandler);


function enterHandler(e:Event):void{
	xPos = this.mouseX;
	yPos = this.mouseY;
	
}

function mouseDownHandler(event:MouseEvent):void {
line.graphics.lineStyle(2);
stage.addEventListener(MouseEvent.MOUSE_MOVE,movement);
stage.removeEventListener(Event.ENTER_FRAME, enterHandler);

}
function mouseUpHandler(event:MouseEvent):void {
line.graphics.clear();
stage.removeEventListener(MouseEvent.MOUSE_MOVE,movement);
stage.addEventListener(Event.ENTER_FRAME, enterHandler);
}
function movement(event:MouseEvent):void {
line.graphics.clear();
line.graphics.moveTo(xPos,yPos);
line.graphics.lineStyle(15); 
line.graphics.lineTo(mouseX,mouseY);
}
Bluepear_Design is offline   Reply With Quote
Old 02-18-2012, 02:07 PM   #8
peptobismol
Senior Member
 
Join Date: Oct 2005
Posts: 746
Default

try
Code:
import flash.events.Event;

var line:Sprite;
var xPos:int;
var yPos:int;
line = new Sprite();
addChild(line);

stage.addEventListener(MouseEvent.MOUSE_DOWN,mouseDownHandler);
stage.addEventListener(MouseEvent.MOUSE_UP,mouseUpHandler);



function mouseDownHandler(event:MouseEvent):void {
line.graphics.lineStyle(2);
xPos = this.mouseX;
yPos = this.mouseY;
stage.addEventListener(MouseEvent.MOUSE_MOVE,movement);

}

function mouseUpHandler(event:MouseEvent):void {
line.graphics.clear();
stage.removeEventListener(MouseEvent.MOUSE_MOVE,movement);

}
function movement(event:MouseEvent):void {
line.graphics.clear();
line.graphics.moveTo(xPos,yPos);
line.graphics.lineStyle(15); 
line.graphics.lineTo(mouseX,mouseY);
}


stop();
If that doesn't work, switch back to the touch events.
peptobismol is offline   Reply With Quote
Reply


Thread Tools
Display Modes Rate This Thread
Rate This Thread:

Posting Rules
You may not post new threads
You may not post replies
You may not post attachments
You may not edit your posts

BB code is On
Smilies are On
[IMG] code is On
HTML code is Off

Forum Jump


All times are GMT. The time now is 01:53 PM.

///
Follow actionscriptorg on Twitter

 


Powered by vBulletin® Version 3.8.5
Copyright ©2000 - 2014, Jelsoft Enterprises Ltd.
Ad Management plugin by RedTyger
Copyright 2000-2013 ActionScript.org. All Rights Reserved.
Your use of this site is subject to our Privacy Policy and Terms of Use.