Warning: file_get_contents(/data/phpspider/zhask/data//catemap/5/actionscript-3/6.json): failed to open stream: No such file or directory in /data/phpspider/zhask/libs/function.php on line 167

Warning: Invalid argument supplied for foreach() in /data/phpspider/zhask/libs/tag.function.php on line 1116

Notice: Undefined index: in /data/phpspider/zhask/libs/function.php on line 180

Warning: array_chunk() expects parameter 1 to be array, null given in /data/phpspider/zhask/libs/function.php on line 181
Actionscript 3 在AS3中的固定框中安装电影剪辑阵列_Actionscript 3_Movieclip - Fatal编程技术网

Actionscript 3 在AS3中的固定框中安装电影剪辑阵列

Actionscript 3 在AS3中的固定框中安装电影剪辑阵列,actionscript-3,movieclip,Actionscript 3,Movieclip,我有一系列的电影唇,可以只有一个,但也可以有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.graphi

我有一系列的电影唇,可以只有一个,但也可以有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]);
}
如何在满足以下要求的同时,将阵列中的所有movieclips添加到框中

电影唇可以调整大小,但必须保持其高宽比 电影唇部不能重叠 movieclip不得超过盒式movieclip的边界 电影之间必须有一些空间,比如说,10px 必须尽可能有效地利用盒式电影剪辑的空间 movieclips不必按相同的顺序排列,例如movieClipsArray[0]可以位于左上角,也可以位于右下角或中间的某个位置
很抱歉,我自己没有做太多,但我只是不知道从哪里开始,如果我把事情复杂化了,我不知道,但我个人会这样做:

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]);

}
}

请记住,我没有勾选这个,我只是写它来帮助你走上正确的轨道。

所有的电影唇都是相同大小的吗?所以如果所有的电影唇都不能放进盒子里,可以调整大小并缩小尺寸?@Marcela不,它们不是t@Andrei-是的,只要它们保持相同的高度/宽度比,例如600x300的movieclip可以调整为100x50,但不能调整为150x150。此任务有两种解决方案。一个是优化,这并不容易。另一种方法是可行的:按大小对所有盒子进行排序,从最大的开始,如果不合适,就挤压它。把它放在左上角。在此之后,您将得到最多三个容器,而不是一个。这些是放置框右侧、底部和右下角的空白区域。每一个都成为一个新的容器。现在对剩余的盒子重复,检查它们是否与所有新容器等最匹配。如果两个容器具有相同的侧面,也可以将它们合并回去。如果它们的大小都相同,那么这太容易了,我想它们都可以有不同的尺寸,也可以有不同的宽度/高度ratio@AndreiNikolaenko我认为OP只是为了适应舞台而调整大小,而不是单独调整大小。希望他能澄清,如果需要,我可以编辑我的答案。@Jonan您可能仍然可以使用与我提交的代码类似的代码,但将mcWidth和mcHeight更改为movieClipsArray[I+j]。width和movieClipsArray[I+j]。高度将更接近您想要的。如果你需要我重写,尽管问。