How do you get/set the absolute position of a MovieClip in Flash/AS3? And by absolute, I mean its position relative to the stage's origo.
I currently have this setter:
class MyMovieClip extends MovieClip
{
function set xAbs(var x:Number):void
{
this.x = -(this.parent.localToGlobal(new Point()).x) + x;
}
}
This seems to work, but I have a feeling it requires that the Stage is left aligned.
However, I don't have a working getter. This doesn't work:
public function get xAbs():Number
{
return -(this.parent.localToGlobal(new Point()).x) + this.x; // Doesn't work
}
I'm aiming for a solution that works, and works with all Stage alignments, but it's tricky. I'm using this on a Stage which is relative to the browser's window size.
EDIT: This works for a top-left aligned stage; not sure about others:
public function get AbsX():Number
{
return this.localToGlobal(new Point(0, 0)).x;
}
public function get AbsY():Number
{
return this.localToGlobal(new Point(0, 0)).y;
}
public function set AbsX(x:Number):void
{
this.x = x - this.parent.localToGlobal(new Point(0, 0)).x;
}
public function set AbsY(y:Number):void
{
this.y = y - this.parent.localToGlobal(new Point(0, 0)).y;
}