Cannot get coordinates in respect to stage

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

trace( _root.stageX(this) );

where it is defined on the main timeline as:

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:

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:

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

Could anyone help please? :slight_smile: