[AS3] Create Objects in a loop?

Subscribe to [AS3] Create Objects in a loop? 3 posts

avatar for harlytrav harlytrav 83 posts
Flag Post

Hi there, I was wondering if there was a way to create an object in a for loop (ActionScript 3)

Code:

var gridpiece=function(){}
gridpiece.prototype.disx;
gridpiece.prototype.disy;
//Yes I do my classes inside the document

var gridpiece1=new gridpiece

//end

So, what if I wanted to create 40 gridpieces in a for loop? How would that be done?

 
avatar for qwerber qwerber 4717 posts
Flag Post

this is not Javascript.

Use Classes.

 
avatar for BraydenBlack BraydenBlack 271 posts
Flag Post
 

gridWidth = 15;
gridHeight = 15;

mapArray = new Array();

var row, col:int = 0;

for(row = 0; row < gridWidth; row++) {
	mapArray[row] = new Array();
	for(col = 0; col < gridHeight; col++) {					
		mapArray[row][col] = new Object();
	}
}

Basically creates a 2D array of objects in AS3.