5 Replies Latest reply on Jun 11, 2013 1:03 PM by Pippa01

    How do I set a variable within a 'for' loop grid array

    Pippa01

      I'm afraid I'm stuck again!

       

      The next stage in the animation that I'm working on,  is to set up a boolean, 'drilled = false', so that all instances of the attachMovie ('openCircle') have a boolean 'drilled = false' associated with them. Then when someone clicks on one of the instances of the attachMovie ('openCircle'), the boolean becomes 'drilled = true', but only for that instance that has been clicked.

       

      What I've done is to set the variable (boolean)(highlighted in bold below) within both 'for' loops within the grid array, but it just returns an undefined value. Do I need to setup a separate array? (see code below):-

       

      //set up grid for solid array

      var spacing:Number = 5.75;

      var cols:Number = 20; // number of columns in grid

      var rows:Number = 20; // number of rows in grid

      var leftMargin:Number = 154;

      var topMargin:Number = 169;

      var depth:Number = 100; // starting point for depth

      var drilled:Boolean;

       

       

      for (i=1; i<=rows; i++) {                                                                                                         

      for (j=1; j<=cols; j++) {                                                                                                                              

                drilled[rows,cols]=false;

                          trace(drilled);

       

       

                current = attachMovie("openCircle_mc", "openCircle_mc"+i+"_"+j, depth++);

                current._x = leftMargin + ((i-1) * (spacing + current._width));

                current._y = topMargin + ((j-1) * (spacing + current._height));

                current.row=i;

                current.col=j;

      //          current.oil = Math.floor(Math.random()*1.1);  // about 1/10 objects have oil=1, 9/10 oil=0

                

                //open circle initially invisible, visible on rollOver

                current._alpha = 0;

                current.onRelease=function(){

                          trace(this.row+" "+this.col);

         current.drilled = true;

                }

                current.onRollOver = function() {

                                       this._alpha = 100;

                                      }

                

                current.onRollOut = function() {

                                       this._alpha = 0;

                                      }

       

      }

      }

      I'd be grateful for any help. Thanks.