Exit
  • Global community
    • Language:
      • Deutsch
      • English
      • Español
      • Français
      • Português
  • 日本語コミュニティ
  • 한국 커뮤니티
0

Touch Coordinates without e.stageX and e.stageY

Explorer ,
Feb 09, 2013 Feb 09, 2013

So I have a virtual camera, and eventually I get off the stage.  I used to use e.stageX and e.stageY to get the coordinates of the touch, but I cannot do that anymore because I am no longer on the stage.  How do I get the coordinates of the user's touch when they are not touching the stage?  Surely there is a way, because if there wasn't, I'd have to come up with some extremely - difficult equasion, right?  But I want the simple way, or at least adobe can make a keyword for it, because I cannot rely on the stage for everything.

TOPICS
ActionScript
1.8K
Translate
Report
Community guidelines
Be kind and respectful, give credit to the original source of content, and search for duplicates before posting. Learn more
community guidelines
Community Expert ,
Feb 09, 2013 Feb 09, 2013

there are also e.localX and e.localY among other properties.

Translate
Report
Community guidelines
Be kind and respectful, give credit to the original source of content, and search for duplicates before posting. Learn more
community guidelines
Explorer ,
Feb 09, 2013 Feb 09, 2013

I can't seem to understand the use of e.localX and e.localY.  Can you explain?

Translate
Report
Community guidelines
Be kind and respectful, give credit to the original source of content, and search for duplicates before posting. Learn more
community guidelines
Community Expert ,
Feb 09, 2013 Feb 09, 2013

those are the coordinates local to the event dispatching object.

so, if you had a movieclip at 400,500 and you clicked on the registration point of that movieclip:

e.stageX = 400+the movieclip's registration point's x

e.stageY = 500+the movieclip's registartion point's y

e.localX = 0;

e.localY = 0;

Translate
Report
Community guidelines
Be kind and respectful, give credit to the original source of content, and search for duplicates before posting. Learn more
community guidelines
Explorer ,
Feb 09, 2013 Feb 09, 2013

Okay, I got this, so the user is dragging their finger across the screen, and then the virtual camera brings it off the stage, how would I calculate the coordinates?  I tried localX and localY, but it returned a very incorrect value:

var touchX:Number;

var touchY:Number;

/* Enter Frame Event

Executes the function fl_EnterFrameHandler defined below each time the playhead moves into a new frame of the timeline.

Instructions:

1. Add your custom code on a new line after the line that says "// Start your custom code" below.

The code will execute when the playhead moves into a new timeline frame.

*/

addEventListener(Event.ENTER_FRAME, fl_EnterFrameHandler);

function fl_EnterFrameHandler(event:Event):void

{

          //Start your custom code

          // This example code displays the words "Entered frame" in the Output panel.

          na.x = touchX;

          na.y = touchY;

          // End your custom code

}

Multitouch.inputMode = MultitouchInputMode.TOUCH_POINT;

but.addEventListener(TouchEvent.TOUCH_BEGIN, movesprite);

but.addEventListener(TouchEvent.TOUCH_MOVE, movespritee);

function movesprite(e:TouchEvent):void

{

          touchX = e.localX;

          touchY = e.localY;

}

function movespritee(e:TouchEvent):void

{

          touchX = e.localX;

          touchY = e.localY;

}

So, my guess is there should be an equation like 'e.stageX - vcam.x;' ?

Translate
Report
Community guidelines
Be kind and respectful, give credit to the original source of content, and search for duplicates before posting. Learn more
community guidelines
Community Expert ,
Feb 09, 2013 Feb 09, 2013

what's na and what is its parent?

Translate
Report
Community guidelines
Be kind and respectful, give credit to the original source of content, and search for duplicates before posting. Learn more
community guidelines
Explorer ,
Feb 10, 2013 Feb 10, 2013

[edit]

I now see the movieclip NA goes toward the registration point of vcam a bit.

[/edit]

Na is the movieclip that has the coordinates of touchx and touchy, also i found out that my vcam scales the stage and makes stagex and stagey return the wrong value even when on the stage

So here's my problem: somewhere in this code, it copies the bitmap data of the stage and scales it, so I'm unable to get the right coordinates:

visible=false;

parent.cacheAsBitmap=true;

////////////////////////////////////////////////////////////////////////////

// Get stage width and height //////////////////////////////////////////////

var oldScaleMode:String=stage.scaleMode;

stage.scaleMode="exactFit";

var sW:Number=stage.stageWidth;

var sH:Number=stage.stageHeight;

stage.scaleMode=oldScaleMode;

////////////////////////////////////////////////////////////////////////////

// Get Vcam width and height ///////////////////////////////////////////////

var bounds_obj:Object=this.getBounds(this);

var camH:Number=bounds_obj.height;

var camW:Number=bounds_obj.width;

////////////////////////////////////////////////////////////////////////////

// Creat Point for dynamic registration point //////////////////////////////

var rp:Point=new Point(x,y);

////////////////////////////////////////////////////////////////////////////

// Add Event Listeners /////////////////////////////////////////////////////

addEventListener(Event.ENTER_FRAME,camControl);

addEventListener(Event.REMOVED_FROM_STAGE,reset);

////////////////////////////////////////////////////////////////////////////

// Create BitmapData ///////////////////////////////////////////////////////

var bmp:Bitmap;

var myBitmapData:BitmapData=new BitmapData(sW,sH,true,0);

bmp=new Bitmap(myBitmapData);

camControl();

stage.addChild(bmp);

////////////////////////////////////////////////////////////////////////////

////////////////////////////////////////////////////////////////////////////

function camControl(...event):void {

parent.visible=true;

////////////////////////////////////////////////////////////////////////////

// Move the registration point to the vCams current position ///////////////

rp.x=x;

rp.y=y;

////////////////////////////////////////////////////////////////////////////

// Gets the current scale of the vCam //////////////////////////////////////

var h:Number=camH * scaleY;

var w:Number=camW * scaleX;

////////////////////////////////////////////////////////////////////////////

// Gets the stage to vCam scale ratio //////////////////////////////////////

var _scaleY:Number=sH / h;

var _scaleX:Number=sW / w;

////////////////////////////////////////////////////////////////////////////

// Positions the parent ////////////////////////////////////////////////////

x2=w / 2 * _scaleX;

y2=h / 2 * _scaleY;

scaleX2=_scaleX;

scaleY2=_scaleY;

rotation2=- rotation;

////////////////////////////////////////////////////////////////////////////

// Draw bitmap of parent////////////////////////////////////////////////////

myBitmapData.lock();

myBitmapData.fillRect(myBitmapData.rect,0x00);

myBitmapData.unlock();

myBitmapData.draw(stage);

////////////////////////////////////////////////////////////////////////////

// Apply vCam filters to bitmap ////////////////////////////////////////////

bmp.filters=this.filters;

bmp.transform.colorTransform=this.transform.colorTransform;

parent.visible=false;

}

function reset(e:Event):void {

////////////////////////////////////////////////////////////////////////////

// Cleans up data for garbage collection ///////////////////////////////////

removeEventListener(Event.ENTER_FRAME,camControl);

removeEventListener(Event.REMOVED_FROM_STAGE,reset );

stage.removeChild(bmp);

myBitmapData.dispose();

bmp=null;

////////////////////////////////////////////////////////////////////////////

// Resets parent properties ////////////////////////////////////////////////

parent.scaleX=1;

parent.scaleY=1;

parent.x=0;

parent.y=0;

parent.rotation=0;

parent.visible=true;

}

function set x2(value:Number):void {

var p:Point=parent.parent.globalToLocal(parent.localToGlobal(rp));

parent.x+= value - p.x;

}

function get x2():Number {

var p:Point=parent.parent.globalToLocal(parent.localToGlobal(rp));

return p.x;

}

function set y2(value:Number):void {

var p:Point=parent.parent.globalToLocal(parent.localToGlobal(rp));

parent.y+= value - p.y;

}

function get y2():Number {

var p:Point=parent.parent.globalToLocal(parent.localToGlobal(rp));

return p.y;

}

function get scaleX2():Number {

return parent.scaleX;

}

function set scaleX2(value:Number):void {

setProperty2("scaleX",value);

}

function get scaleY2():Number {

return parent.scaleY;

}

function set scaleY2(value:Number):void {

setProperty2("scaleY",value);

}

function get rotation2():Number {

return parent.rotation;

}

function set rotation2(value:Number):void {

setProperty2("rotation",value);

}

function setProperty2(prop:String,n:Number):void {

var a:Point=parent.parent.globalToLocal(parent.localToGlobal(rp));

parent[prop]=n;

var b:Point=parent.parent.globalToLocal(parent.localToGlobal(rp));

parent.x-= b.x - a.x;

parent.y-= b.y - a.y;

}

Translate
Report
Community guidelines
Be kind and respectful, give credit to the original source of content, and search for duplicates before posting. Learn more
community guidelines
Community Expert ,
Feb 10, 2013 Feb 10, 2013

that's more code than i can correct in a forum.

Translate
Report
Community guidelines
Be kind and respectful, give credit to the original source of content, and search for duplicates before posting. Learn more
community guidelines
Explorer ,
Feb 10, 2013 Feb 10, 2013

I'm not asking you to correct it, I'm just showing what's in my virtual camera code that I'm trying to look for a code that's scaling the stage that I can change so it doesn't affect my touch events.

Translate
Report
Community guidelines
Be kind and respectful, give credit to the original source of content, and search for duplicates before posting. Learn more
community guidelines
Explorer ,
Feb 10, 2013 Feb 10, 2013
LATEST

Here, watch this video, you'll understand much better about my problem:

http://www.youtube.com/embed/jkk0k6HvDa4

Translate
Report
Community guidelines
Be kind and respectful, give credit to the original source of content, and search for duplicates before posting. Learn more
community guidelines