讓多個影片剪輯能夠在網格上移動,一旦拖動它,它就會重複,並且「原始」仍然保留。 是什麼導致它在我的代碼中重複?Flash as3 Var movieClip複製品
import flash.display.MovieClip
[SWF(width = 1300, height = 1000)]
var tileSize: int = 100;
var cols: int = stage.stageWidth/tileSize;
var rows: int = stage.stageHeight/tileSize;
var grid: Sprite = Sprite(addChild(new Sprite()));
grid.graphics.lineStyle(0, 0x000000, 0);
var i: int = 0;
for (i = 1; i < cols; i++) {
var posX: Number = i * tileSize
grid.graphics.moveTo(posX, 0);
grid.graphics.lineTo(posX, stage.stageHeight);
}
for (i = 1; i < rows; i++) {
var posY: Number = i * tileSize
grid.graphics.moveTo(0, posY);
grid.graphics.lineTo(stage.stageWidth, posY);
var ball: the_ball = new the_ball();
addChild(ball);
ball.x = tileSize * 5;
ball.y = tileSize * 5;
ball.buttonMode = true;
ball.addEventListener(MouseEvent.MOUSE_DOWN, onDown);
function onDown(evt: MouseEvent): void {
addEventListener(Event.ENTER_FRAME, onRunSnapping);
}
function onRunSnapping(evt: Event): void {
ball.x = Math.round(mouseX/tileSize) * tileSize;
ball.y = Math.round(mouseY/tileSize) * tileSize;
}
stage.addEventListener(MouseEvent.MOUSE_UP, onUp);
function onUp(evt: MouseEvent): void {
removeEventListener(Event.ENTER_FRAME, onRunSnapping);
}
}
它是一個框架腳本?如果是,您的時間表上有多少幀?附:格式化您的代碼。未格式化的代碼真的很難遵循。 – Organis
您的代碼僅在舞臺上增加了1個球。怎麼會有多個可拖動的影片剪輯? –
@ManuelOtto它位於循環內部,但由於格式不當而不明顯。 – Organis