import flash.display.Sprite;
import flash.geom.Point;
var s:Sprite = new Sprite();
s.x = 100;
s.y = 100;
drawRect(s,0x0000ff,300);
addChild(s);
var s1:Sprite = new Sprite();
s1.x = 100;
s1.y = 100;
drawRect(s1,0x00ff00);
s.addChild(s1);
function drawRect(s:Sprite,color:uint,w:int =100):void
{
s.graphics.beginFill(color);
s.graphics.drawRect(0,0,w,w);
}
//trace(s.localToGlobal(new Point(10,10)));
trace(s1.localToGlobal(new Point(10,10))); // (x=210, y=210)
例如
s1.localToGlobal(new Point(10,10))
相当于把s1原封不动取出来放到stage上,相对于new point的位置,如果是new Point(0,0),则相对于舞台原点
trace(s1.globalToLocal(new Point(0,0))); // (x=-200, y=-200)
new point的点相当于stage坐标
(2).globalToLocal (point) point为全局坐标,计算出该point相当于(2)的坐标
相当于把舞台的点原封不动放入到目标元件内部,
trace(s1.globalToLocal(new Point(0,0))); // (x=-200, y=-200)
new point的点相当于内部的点
【坐标都是相对而言,参考系】