1

Hi i have some movieclips like this one: game_mc.substage_mc.rightHand and inside the rightHand i have a thread_mc like this:

game_mc.substage_mc.rightHand.thread_mc

Ok so here is the thing, i need to access the thread.x and thread.y position related to the stage or substage_mc i don´t really care, but if i do this:

trace(game_mc.substage_mc.rightHand.thread_mc.x);

I only get the thread position related to the rightHand and not to the stage. Any help here?.

Sam DeHaan
  • 10,246
  • 2
  • 40
  • 48
ershin69
  • 96
  • 3
  • 16

3 Answers3

2

there is a function on the DisplayObject class called localToGlobal

that will give you the coordinates, but you need to keep scale in mind

Daniel
  • 34,125
  • 17
  • 102
  • 150
  • Great!, i don´t know why i tried that and didn´t work the first time, thanks! now i can move on ^^. – ershin69 Mar 22 '12 at 15:12
  • hey daniel i don´t know if its ok to ask here again, but do you know any way of getting the position of a movieClip related to another? i don´t know why but the two movieClips i´m comparing have different localToGlobal positions and they are in the same layer but are inside different movieclips – ershin69 Mar 22 '12 at 15:38
  • the trick is to convert localToGlabal and assign to a point, then you go globalToLocal for the movieclip where you want to find the location. using globalToLocal and localToGlobal is a bit confusing to start with, so reading up a bit on it and playing around might help a lot. check out this link, I think that's the same issue you might be having http://www.orlandmedia.com/blog/tutorials/how-to-use-localtoglobal-in-actionscript-3-0/ – Daniel Mar 22 '12 at 15:44
  • @ershin69 have a look at the links in my answer, I posted because is a method a bit tricky to use – Sr.Richie Mar 22 '12 at 16:02
1

You have to use the localToGlobal() method.

Here you can find some useful explanation:

Understanding localToGlobal

Use localToGlobal in AS3

Sr.Richie
  • 5,680
  • 5
  • 38
  • 62
1

Try localToGlobal:

var posX:int = game_mc.substage_mc.rightHand.thread_mc.x;
var posY:int = game_mc.substage_mc.rightHand.thread_mc.y;
trace(game_mc.substage_mc.rightHand.thread_mc.localToGlobal(new Point(posX, posY));
Miha
  • 301
  • 2
  • 8