0
默認爲(0,0)當執行代碼:精靈(X,Y)在AS3
var cont:Sprite = new Sprite();
var a:Vector.<int > = Vector.<int > ([1,2]);
var b:Vector.<Number > = Vector.<Number > ([0,0,40,40]);
cont.graphics.lineStyle(5, 0x442299);
cont.graphics.drawPath(a, b);
addChild(cont);
cont.x = 100;
cont.y = 100;
trace("X coordinate of purple line: ", cont.x);
我得到的輸出 「紫色線的X座標:100」
然而,當我測試此代碼並用鼠標繪製從(100,100)中的線(140,140):
var line:Sprite = new Sprite();
stage.addEventListener(MouseEvent.MOUSE_DOWN,mouseDownHandler);
stage.addEventListener(MouseEvent.MOUSE_UP,mouseUpHandler);
var startX:int = -1;
var startY:int = -1;
function mouseDownHandler(event:MouseEvent):void
{
startX = mouseX;
startY = mouseY;
}
function mouseUpHandler(event:MouseEvent):void
{
swype(Vector.<int> ([1,2]), Vector.<Number> ([startX,startY,mouseX,mouseY]));
}
function swype(commands:Vector.<int>, coords:Vector.<Number>):void
{
var container:Sprite = new Sprite();
container.graphics.lineStyle(5, 0x0066CC);
container.graphics.drawPath(commands, coords);
addChild(container);
container.x = 100;
container.y = 100;
trace("X coordinate of blue line: ", container.x);
}
我得到的輸出: 「藍線的X座標:0」
爲什麼當我從屏幕上的鼠標位置獲取座標並將它們添加到矢量中時,Sprite容器的x和y座標默認爲0,0?