Can anyone help me make sense of the following?
I create a few squared sprites and then remove the first one and display the coords. The result is:
(x=0, y=0, w=208, h=40) 0 208
(x=42, y=0, w=166, h=40) 0 166
The x coordinate is still 0, though width has changed, getBounds shows correct values. I would expect x to change as well. Because of the wrong value of x, globalToLocal and localToGlobal work incorrectly.
If you click somewhere on the left side of the second (still visible) rectangle you get:
2 28 (x=2, y=28)
which is good for nothing. The values in brackets should be in stage coords and they are not.
The code:
public function test():void {
var s:Sprite;
var i:int;
var arr:Array = new Array();
for (i = 0; i < 5; ++i)
{
s = new Sprite();
s.graphics.beginFill(0x999);
s.graphics.drawRect(0, 0, 40, 40);
s.graphics.endFill();
s.x = i * 42;
arr.push(s);
addChild(s);
}
trace(this.getBounds(stage), x, width);
removeChild(arr[0]); arr[0] = null;
trace(this.getBounds(stage), x, width);
addEventListener(MouseEvent.CLICK, click);
}
private function click(e:MouseEvent):void {
trace(e.localX, e.localY, localToGlobal(new Point(e.localX, e.localY)));
}