似乎没有针对此的Flash API。所以看起来像是你取两个显示对象,得到它们的全局位置,然后减去差值。
下面是一个函数,它似乎正在工作:
public function distanceBetweenDisplayObjects(source:Object, target:Object):Point {
var sourceRelativePoint:Point;
var sourceLocalToGlobalPoint:Point;
var containerLocalToGlobalPoint:Point;
var x:Number;
var y:Number;
var zeroPoint:Point = new Point(0, 0);
sourceLocalToGlobalPoint = source.localToGlobal(zeroPoint);
containerLocalToGlobalPoint = target.localToGlobal(zeroPoint);
var sourceDifference:Point = sourceLocalToGlobalPoint.subtract(containerLocalToGlobalPoint);
var containerDifference:Point = containerLocalToGlobalPoint.subtract(sourceLocalToGlobalPoint);
return sourceDifference;
}
用法:
var sourceDifference:Point = distanceBetweenDisplayObjects(nestedButton, mainContainer);