Sign In

AS3 – Actionscript 3 – globalToLocal & localToGlobal

I’m hacking to pieces the Open Flash Charts in a project I am working on.

One bit required me to put a Sprite to the same position as another Sprite but under a different Parent DisplayObject. I was using the globalToLocal and localToGlobal methods but couldn’t get it to work. There wasn’t much on the net about how to use this except from basic programming principles.

What cracked it for me was you call the method localToGlobal on the PARENT of the Sprite you want to copy. As follows.

var clone:AxisLabel = g.x_axis.labels.getChildAt(index) as AxisLabel;
var position:Point = label.parent.globalToLocal(clone.parent.localToGlobal(new Point(clone.x,clone.y)));
label.x = position.x;
label.y = position.y;

So I wanted to put my label in the same absolute position as the ‘clone’. So I called localToGlobal on it’s PARENT.

Hope this helps!

Related Posts

Leave a Reply

Your email address will not be published. Required fields are marked *