将数组中的影片剪辑排列到网格 as3 中
Arrange movie clips from an array into grid as3
以下代码旨在将影片剪辑从数组加载到舞台上,并将它们排列成网格形式。
我收到以下错误:
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;
}
}
这只是即兴发挥,您必须接受它并使其满足您的需要。
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;
}
}
以下代码旨在将影片剪辑从数组加载到舞台上,并将它们排列成网格形式。
我收到以下错误:
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;
}
}
这只是即兴发挥,您必须接受它并使其满足您的需要。
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;
}
}