12 Replies Latest reply on Apr 11, 2007 3:52 PM by kglad

    Using Actionscript to generate a grid

      Hello all.

      I am working on a Flash project and have a problem that has turned out to be a real head scratcher for me. I need to create a Flash form that will generate a floorplan grid based upon width and length values entered by the user. I have successfully completed part of the task and I am able to generate a grid based upon the width and length entered by the user.

      Here is my problem: When the Width and Length "units" are entered as feet, I need to generate a grid that displays 1 grid square for every 5 feet of length or width entered, (the scale is 1 square grid = 5 ft so if you entered a 50 ft building length or width the "length or width" side of the grid would be 10 grid units in length). Then, if the user re-enters new values for the width and height and clicks "draw floorplan" again the grid needs to regenerate again at the proper size. Currently my sample generates 1 grid for every foot of length or width entered and will not regenerate properly.

      Below is a link to a sample of where I am so far as well as the Actionscript I am using to control the sample file.

      Can anyone provide some pointers on how to generate the grid with one grid representing 5ft and how to regenerate the grid once new values are input and the "draw floorplan" button is clicked again? (Also, ultimately I need to then send the form data as email.)

      Any help is very much appreciated!

      Link to sample:
      (Try entering 10 width and 10 length then click draw floor plan)

      Here is my actionscript code so far:

      my_button.onPress=function(){if(Number(widthTF.text)>1&&Number(heightTF.text)>1){gridF(Num ber(widthTF.text),Number(heightTF.text))
      function gridF(h,w){
      initX = 0;
      initY = 0;
      counter = 0;
      for (var i = 1; i<=h; i++) {
      for (var j = 1; j<=w; j++) {
      grid_container.attachMovie("cellMC", "cell"+counter, counter);
      grid_container["cell"+counter]._x = initX;
      grid_container["cell"+counter]._y = initY;
      initX += 15;
      initY += 15;
      initX = 0;

      (For clarification: the width input variable is widthTF and height input varible is heightTF.)