# Cannot get coordinates in respect to stage

**URL:** <https://forum.kirupa.com/t/cannot-get-coordinates-in-respect-to-stage/245991>\
**Category:** flash\
**Created:** [December 6, 2007, 3:20am UTC](https://forum.kirupa.com/t/cannot-get-coordinates-in-respect-to-stage/245991 "2007-12-06T03:20:28Z")\
**Posts on this page:** 1\
**Page:** 1

<div class="post-metadata">

**Author:** ![Blommestein](https://avatars.discourse-cdn.com/v4/letter/b/9d8465/32.png) [@Blommestein](https://forum.kirupa.com/u/Blommestein)\
**Post date:** [December 6, 2007, 3:20am UTC](https://forum.kirupa.com/t/cannot-get-coordinates-in-respect-to-stage/245991/1 "2007-12-06T03:20:28Z")

</div>

Okay picture an mc embedded in an unknow amount of parent mcs. With the code put on the mc, I tried this:

```auto
trace( _root.stageX(this) );

```

where it is defined on the main timeline as:

```auto
function stageX(mc:MovieClip):Number
{
    var rx:Number = mc._x;
    if(mc._parent != null)
    {
        var par:MovieClip = mc._parent;
        while(par != null)
        {
            rx += par._x;
            par = par._parent;
        }
    }
    return rx;
}

```

It worked fine until the topchild’s xscale became -100. I tried to edit it a bit but had no luck. I searched some more and found out about localtoGlobal() and tried this:

```auto
function stagePos(mc:MovieClip, type:String):Number
{
    var point:Object = {x: mc._x, y: mc._y};
    while(mc._parent != _root)
    {
        mc = mc._parent;
    }
    mc.localToGlobal(point);
    return (type == "y") ? point.y : point.x;
}

```

This too does not work when called from the embedded mc as:

```auto
trace( _root.stagePos(this,"x") );

```

Could anyone help please? 🙂
