我有一个更大的项目,但我可以将问题缩小到这个例子:
public function Main()
{
var myContainer:Sprite = new Sprite;
myContainer.graphics.beginFill(0xFFFFFF);
myContainer.graphics.lineStyle(1);
myContainer.graphics.drawRect(10, 10, 300, 300);
myContainer.graphics.endFill();
addChild(myContainer);
trace('Container coords: ' + myContainer.x + ' ' + myContainer.y);
trace('Instance coords: ' + getChildAt(numChildren - 1).x + ' ' + getChildAt(numChildren - 1).y);
var spr:Sprite = new Sprite;
spr.graphics.beginFill(0xFF0000);
spr.graphics.lineStyle(1);
spr.graphics.drawCircle(30, 30, 10);
spr.graphics.endFill();
myContainer.addChild(spr);
trace('Child coords: ' + spr.x + ' ' + spr.y);
trace('Child instance coords: ' + myContainer.getChildAt(myContainer.numChildren - 1).x + ' ' + myContainer.getChildAt(myContainer.numChildren - 1).y);
}
输出是这样的:
Container coords: 0 0
Instance coords: 0 0
Child coords: 0 0
Child instance coords: 0 0
有人可以解释如何在精灵中获取子精灵的实际坐标(本地或全局,我知道你可以在两者之间转换)?