attachMovie() Method

Im trying to use a loop to set up 4 rows of 10 “blocks” in flash…I have a movieclip with an idName of “Block”. My idea was to imbed the singular row of blocks loop within the loop of rows so that it generates the four rows quickly and all at once…I was trying to use the following code but it doesn’t work…it seems to show only the last block in the loop and i did some echo checking at the end and found that after the loop completes, there are no activated blocks…I found this by doing another loop and tracing all the blocks _x properties which all returned undefined…even the last one which was still visible…:

/* Constants Section */
var NumBlocks = 10;
var NumRows = 4;
var StageWidth = Stage.width;
var StageHeight = Stage.height;
var BlockWidth = StageWidth/NumBlocks;
var BlockHeight = StageHeight/30;
var BlockName = " ";
/* End Constants Section */
for (RowCount = 1; RowCount <= NumRows; RowCount += 1) {
	for (BlockCount = 1; BlockCount <= NumBlocks; BlockCount += 1) {
		BlockName = "Block"+BlockCount+"Row"+RowCount;
		with (_root.BlockName) {
			_x = BlockWidth * BlockCount - BlockWidth;
			_y = BlockHeight * RowCount - BlockHeight;
			_width = BlockWidth;
			_height = BlockHeight;

so please tell me if there are any errors that really stick out at you…and if you do find an error please make sure that its one that might fix my problem because typically after people see one reply they do not read the post…which kinda screws me over…thanks

Welcome, riveroaks. =)

I think you’d only need to replace this line:

with (_root.BlockName) {

With this one:

with (_root[BlockName]) {

See for more info. :wink:

wow…im surprised that worked…why did it work? I read the thread in that link but I still don’t understand…aren’t those brackets used for arrays when referencing names? I know that im basically creating my own array but i never defined my rows of blocks as arrays so why would I use the brackets? This isn’t a very crucial issue but if anyone could take a sec to explain it, id appreciate it.

You’re welcome. :stuck_out_tongue:

And well, you should read the thread again if you didn’t understand it… I honestly cannot explain it better than that. Sorry. :-\

…Good luck! :wink: