AS2 > AS3 migratrion issues re. addChild()

Hi, forgive me making a nebulous and slightly rambling post, but I’m a reasonably proficient AS2 coder trying to programme in AS3 for the first time, and have not gone for before encountering a problem.

I have a function in AS2 that creates a grid, accepting number of rows, number of columns, row height, row width, x offest and y offset as arguments.

Here it is - it’s reasonably straightforward, and I hope, makes sense (‘mapSq’ is a square movie clip):

createMap = function (rows, cols, colW, rowH, offsetX, offsetY) {
	_root.createEmptyMovieClip("mapHolder", 1);
	trace ("Creating map with " + rows + " rows and " + cols + " colums");
	for (i=0; i<rows; i++) {
		for (j=0; j<cols; j++) {
			// attach squares
			mapHolder.attachMovie("mapSq", "mapSq_"+i+"_"+j, mapHolder.getNextHighestDepth());
			mapHolder["mapSq_"+i+"_"+j]._width = colW;
			mapHolder["mapSq_"+i+"_"+j]._height = rowH;
			mapHolder["mapSq_"+i+"_"+j]._x = (j*colW)+offsetX;
			mapHolder["mapSq_"+i+"_"+j]._y = (i*rowH)+offsetY;
		}
	}
	// draw grid lines
	mapHolder.createEmptyMovieClip("mapGrid", mapHolder.getNextHighestDepth());
	for (i=0; i<rows+1; i++) {
		with(mapHolder.mapGrid) {
			lineStyle(1, 0x6666cc, 100, true, "normal", "square", "miter", 1);
			moveTo(0+offsetX, (i*rowH)+offsetY);
			lineTo((cols*colW)+offsetX, (i*rowH)+offsetY);
		}
		for (j=0; j<cols+1; j++) {
			with(mapHolder.mapGrid) {
				lineStyle(1, 0x6666cc, 100, true, "normal", "square", "miter", 1);
				moveTo((j*colW)+offsetX, 0+offsetY);
				lineTo((j*colW)+offsetX, (rows*rowH)+offsetY);
			}
		}
	}
}

// createMap arguments: rows, columns, row height, col width, x offset, y offset 
createMap(10, 20, 12, 16, 40, 15);

I’ve decided that as a first project I want to convert this to AS3, and import it as a Class. So I’ve created a new .as file with the following code:

package com.mysite.movieclip {
    import flash.display.MovieClip;
    public class DrawMapGrid {
        public function DrawMapGrid (rows, cols) {
            trace("Draw map with " + rows + " rows and " + cols + " columns");
        }
    }
}

and in my .fla file, I have:

import com.mysite.movieclip.DrawMapGrid;
var newMap:DrawMapGrid = new DrawMapGrid(5, 10); 

This results in a trace of “Draw map with 5 rows and 10 columns” - so far, so good. The problem comes when I try to attach the map square movie clip. In my .fla file I have the square as a movie clip, and in the Linkage Properties dialogue box I have “Class: mapSq”. However, when I add the following lines to public function DrawMapGrid:

var newMapSq:mapSq = new mapSq();   
this.addChild (newMapSq);

…I get the error code “1061: Call to a possibly undefined method addChild through a reference with static type com.mysite.movieclip:DrawMapGrid”.

Which is as far as I’ve got. What do I have to do? Do I have to set up another Class file to define/handle mapSq? Or am I right in trying to do it from DrawMapGrid?

I’m sure the answer is pretty straightfoward, but it’s not hitting me just yet.