I have 2 input text box on my stage width_txt, height_txt and a movieClip called *Floor. *Using my code I can draw a grid with equal grid spacing. I have 2 problems, first my grid lines don’t refresh or redraw when I change the values. Secondly, as long as I have an even number floor space like 10x10 or 12x12 the grid draws correctly, if I try and set a floor size of 11x9 or 13x10, the grid does not draw correctly. My code may not be the best approach, so any help appreciated.
// yZ = number of grid lines along y axis
// xZ = number of grid lines along x axis
//
// listen for width text change
var txtListener:Object = new Object();
txtListener.onChanged = function(textfield_txt:TextField) {
floor._width = Number(width_txt.text*24);
trace(floor._width);
width_txt.autoSize = true;
xZ = Number(width_txt.text);
xZ = xZ+1;
//trace(xZ);
drawXgrid();
};
width_txt.addListener(txtListener);
// listen for height text change
var txtListener:Object = new Object();
txtListener.onChanged = function(textfield_txt:TextField) {
//trace(textfield_txt._name+" changed and notified myListener");
floor._height = Number(height_txt.text*24);
trace(floor._height);
height_txt.autoSize = true;
yZ = Number(height_txt.text);
yZ = yZ+1;
//trace(yZ);
drawYgrid();
};
height_txt.addListener(txtListener);
// draw floor grid
drawXgrid = function () {
for (ix=0; ix<xZ; ix++) {
this.createEmptyMovieClip("temp", this.getNextHighestDepth());
temp._x = floor._x-floor._width/2;
temp._y = floor._y-floor._height/2;
temp.lineStyle(1, 0x000000, 100);
// x lines
temp.moveTo(ix*24, 0);
temp.lineTo(ix*24, floor._width);
}
};
drawYgrid = function () {
for (iy=0; iy<yZ; iy++) {
this.createEmptyMovieClip("temp", this.getNextHighestDepth());
temp._x = floor._x-floor._width/2;
temp._y = floor._y-floor._height/2;
temp.lineStyle(1, 0x000000, 100);
// y lines
temp.moveTo(0, iy*24);
temp.lineTo(floor._height, iy*24);
}
};