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!

Random Posts

Posted on November 18, 2009 at 8:00 pm by Jordan Carter · Permalink
In: Actionscript 3 · Tagged with: , ,

One Response

Subscribe to comments via RSS

  1. Written by Bob
    on January 14, 2010 at 11:03 am
    Permalink

    Thank you, You have just saved me from wanging my laptop out of the window!

Subscribe to comments via RSS

Leave a Reply