以下代码旨在将数组中的影片剪辑加载到舞台上,并将它们排列成网格形式。
我收到以下错误:
Error #1034: Type Coercion failed: cannot convert animal1$ to flash.display.MovieClip.
(Andrew Sellenrick提供的答案中使用的代码)
var columns = 4;
var rowHeight = 50;
var columnWidth = 1000;
var currentRow = 0;
var currentColumn = 0;
var animalCards = [animal1, animal2, animal3, animal4, animal5, animal6, animal7, animal8, animal9];
for (var i = 0; i < animalCards.length; i++) {
var card = animalCards[i];
card.x = currentColumn * columnWidth;
card.y = currentRow * rowHeight;
addChild(animalCards[i]);
currentColumn++;
if (currentColumn == columns) {
currentRow++;
currentColumn = 0;
}
}
答案 0 :(得分:0)
这只是在袖口之外,您必须接受并使其适合您的需要。
var columns = 4;
var rowHeight = 50;
var columnWidth = 50;
var currentRow = 0;
var currentColumn = 0;
var listOfMovieClips = [clip,clip,clip,...];
for (var i = 0 ; i < listOfMovieClips.length ; i++){
var mc = listOfMovieClips[i];
mc.x = currentColumn * columnWidth;
mc.y = currentRow * rowHeight;
addChild(listOfMovieClips[i]);
currentColumn++;
if (currentColumn == columns){
currentRow++;
currentColumn = 0;
}
}