Reputation: 24580
There are some scenarios where we need to translate a local point in a displayObject to its parent. When the displayObject is not rotated or scaled, the result is calculated easily:
var xAtParent:Number= displayObject.x+ localX;
var yAtParent:Number= displayObject.y+ localY;
// where localX& localY are with respect to displayObject
But, when the displayObject is rotated or scaled, its not directly calculated, so the question is, Is there out of the box solution in action script 3 to solve this issue?
Upvotes: 0
Views: 38
Reputation: 19136
Because it's built on a display list with affine (Matrix) transforms, Flash provides easy-to-use coordinate space transformation functions. To go from src
coordinate system to dst
coordinate system (assuming both src
and dst
are DisplayObject
s on the stage):
var p:Point = new Point(src_local_x, src_local_y);
p = src.localToGlobal(p);
p = dst.globalToLocal(p);
// p.x is dst_local_x
// p.y is dst_local_y
You can also easily get the bounds of any src
object in the local coordinate space of any other dst
object:
var dst_local_bounds:Rectangle = src.getBounds(dst);
Upvotes: 1