0
부모 개체에 추가 된 모든 항목을 그리드 구성으로 배치하기 위해 레이아웃 플러그인에서 작업하고 있습니다. 열, 행, 패딩 값을 설정할 수 있어야합니다. 모든 자식 객체를 배열로 푸시므로 루프의 경우 으로 반복합니다. 나는 이미 객체를 배치 할 필요가있는 위치를 확인하기 위해 double for 루프를 사용하려고 시도했지만, 항상 인덱스가 범위를 벗어났습니다. 오류가 발생했습니다. 현재이 코드를 사용하고 내 그리드 형성을 설정하려면 :AS3 - 배열 길이를 기반으로 맞춤 설정할 수있는 행 및 열 값으로 표를 만드시겠습니까?
var COLUMNS:int = vars.columns;
var PADDING:Number = 10;
for(var i:int = 0; i < childs.length; i++)
{
childs[i].x = (i % COLUMNS) * (childs[i].width + PADDING);
childs[i].y = int(i/COLUMNS) * (childs[i].height + PADDING);
}
을 여기에 나는이 플러그인을 사용하고 방법의 예입니다 : 참고 : 추첨 단지의 크기와 스프라이트를 반환 객체는 150 × 150
var container:Sprite = new Sprite();
var obj1:Draw = new Draw({x:0 ,y:0 ,width:_width,height:_height, color:Constants.GREEN});
var obj2:Draw = new Draw({x:0 ,y:0 ,width:_width,height:_height, color:0x2C2C2C});
var obj3:Draw = new Draw({x:0 ,y:0 ,width:_width,height:_height, color:Constants.BLACK});
var obj4:Draw = new Draw({x:0 ,y:0 ,width:_width,height:_height, color:Constants.GREEN});
var obj5:Draw = new Draw({x:0 ,y:0 ,width:_width,height:_height, color:Constants.GREEN});
var obj6:Draw = new Draw({x:0 ,y:0 ,width:_width,height:_height, color:0x2C2C2C});
var obj7:Draw = new Draw({x:0 ,y:0 ,width:_width,height:_height, color:Constants.BLACK});
var obj8:Draw = new Draw({x:0 ,y:0 ,width:_width,height:_height, color:Constants.GREEN});
var obj9:Draw = new Draw({x:0 ,y:0 ,width:_width,height:_height, color:Constants.GREEN});
addChild(container);
container.addChild(obj1);
container.addChild(obj2);
container.addChild(obj3);
container.addChild(obj4);
container.addChild(obj5);
container.addChild(obj6);
container.addChild(obj7);
container.addChild(obj9);
Layout.setLayout(new GridLayout(container, {columns:4, rows:10, spacing:2}));
사람은 모든 객체가 이전 채워진 배열에 의해 검색됩니다 고정 열, 행 간격이 더 나은 그리드 루프를 만드는 방법에 대한 생각이있어?