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!

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

4 Responses

  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!

  2. Written by arne
    on April 22, 2011 at 5:55 am
    Permalink

    it’s helpful!
    thank for this post

  3. Written by Entipe
    on April 30, 2011 at 8:33 am
    Permalink

    Thanks ! You saved my hairs!

  4. Written by Joey Clover
    on May 2, 2011 at 12:12 pm
    Permalink

    and 1 year later, you saved my ass too. You are awesome!

Leave a Reply