我有一系列的动画片段(可能只有一个,但也可能有100个)和舞台上一个固定宽度和高度的大动画片段(它不能调整大小)。
var boxWidth:int = 500
var boxHeight:int = 300
var box:MovieClip = new Movieclip;
box.graphics.beginFill(0x444444);
box.graphics.drawRect(
0,
0,
boxWidth,
boxHeight
);
box.graphics.endFill();
addChild(box);
var movieClipsArray:Array = []; //dynamic number of movieclips
var movieClipsSpacing:int = 10;
for(var i:String in movieClipsArray){
//calculate x, y, width, and height
box.addChild(movieClipsArray[i]);
}
如何在满足以下要求的同时将数组中的所有动画片段添加到框中?
10px
)movieClipsArray[0]
可以位于左上方,但也可以位于右下角或中间某处抱歉我自己没有做太多,但我不知道从哪里开始
答案 0 :(得分:0)
Dunno,如果我对这一点感到困惑,但我个人会这样做:
var boxWidth:int = 500;
var boxHeight:int = 300;
// each column and row of equally sized movieclip would be 5/7 and 3/7 of the width/height of the box respectively.
mcColumns = ((movieClipsArray.length / 7) * 5); // tells you how many columns
mcRows = ((movieClipsArray.length / 7) * 3); // tells you how many rows
//calculate width
var availableWidth = boxWidth - (mcColumns * 10); //width available after 10px spaces
var mcWidth:int = availableWidth / mcColumns; //width of each box
//calculate height
var availableHeight = boxHeight - (mcRows * 10); //height available after 10px spaces
var mcHeight:int = availableHeight / mcRows; //height of each box
for(var i:int = 0; i<mcColums; i++;){
for(var j:int = 0; i<mcRows; i++;){
//calculate x
movieClipsArray[i+j].width = mcWidth;
movieClipsArray[i+j].x = (availableWidth / mcWidth) * i;
movieClipsArray[i+j].x += 10 * i; //adds the space
//calculate y
movieClipsArray[i+j].height = mcHeight;
movieClipsArray[i+j].y = (availableHeight /mcWidth) * j;
movieClipsArray[i+j].y += 10 * j; //adds the space
box.addChild(movieClipsArray[i+j]);
}
}
请记住,我还没有检查过这个,我只是为了帮助您走上正轨而写下来。