Skip to main content
Inspiring
June 13, 2013
Answered

Problems with an array (attachMovie)

  • June 13, 2013
  • 1 reply
  • 1548 views

I've created a 20 x 20 grid of objects (openCircles). They're set to 'alpha = 0', then 'alpha = 100' on rollover. This works for all of them except for the final one at the coordinate T,20 in the bottom right corner, as I'm not able to rollover over it. To test whether or not they all existed, I set them all to an initial value of 'alpha = 100' and they did all appear, but I'm still unable to rollover the one at T20.

The other problem is that when an 'openCircle' is clicked, a 'filledCircle' (set up as another grid of invisible objects in the same place) is supposed to appear in its place. That doesn't happen. All of the objects are created and exist, using attachMovie, so it's maybe due to some logical error. See code:-

I'd be grateful for any help. Many thanks.

stop();

//The purpose of this experiment is to locate a trap of oil. Only 30 exploration holes are allowed.

//Use the grid coordinate to locate the borehole and then plot the depth

//Drilled is set to false in the 1st(previous) frame

//Rolling over a grid coordinate will reveal a borehole (open circle).

//Click on the borehole (open circle) to start drilling

          //open circle will be removed

          //drilled is set to true for that coordinate

          //filled circle will appear in its place

//set up variables for grid array of open circles (undrilled) and closed circles (drilled)

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 currentRow:Number = 0;

var currentCol:Number = 0;

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

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

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

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

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

          current2 = attachMovie("filledCircle_mc", "filledCircle_mc"+i+"_"+j, getNextHighestDepth());

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

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

          //open circle initially invisible, then visible on rollOver

          current._alpha = 0;

          //filled circles initially invisible

          currentCol2=(current2._x-leftMargin)/(spacing + current2._width);

          currentRow2=(current2._y-topMargin)/(spacing + current2._height);

                                 if (drilled[currentCol,currentRow]==true){

                                                  current2._alpha = 100;

                                                  }else{

                                                            current2._alpha=0;

                                                            }

          //open circle visible on rollover

          current.onRollOver = function() {

                                 this._alpha = 100;

                                 currentCol=(this._x-leftMargin)/(spacing + current._width);

                                 trace("current column ="+currentCol);

                                 currentRow=(this._y-topMargin)/(spacing + current._height);

                                 trace("current row ="+currentRow);

                                 if (drilled[currentCol,currentRow]==false){

                                          trace("Click on the grid point to drill at "+rowLabel[currentRow]+","+colLabel[currentCol]);

                              }else{

                                          trace("Click on the grid point to review the core at "+rowLabel[currentRow]+","+colLabel[currentCol]);

                              }     //end 'if-else'

          }

          //open circle invisible on rollout

          current.onRollOut = function() {

                                 this._alpha = 0;

                                 trace("No grid point selected")

           }

          //click on open circle - variable drilled becomes true

          current.onRelease=function(){

                    drilled[currentCol,currentRow]=true;

                    trace(drilled[currentCol,currentRow]);

                    this.removeMovieClip();

          }

}

}

This is an image of the grid showing an 'openCircle' visible when rolled over

This topic has been closed for replies.
Correct answer Ned Murphy

THe only reason I can see why the last would not react to being rolled over would be due to something blocking it.  If I run your code I can roll over the object and have its alpha change.

As far as the filled version not appearing, I do not see anything in your code that would tell it to become visible.  All you do is set the element of the drilled array relative to that position 19/19 to true.  That will not affect any object.  You have to target the object in and set its _alpha to be true.

1 reply

Ned Murphy
Ned MurphyCorrect answer
Legend
June 13, 2013

THe only reason I can see why the last would not react to being rolled over would be due to something blocking it.  If I run your code I can roll over the object and have its alpha change.

As far as the filled version not appearing, I do not see anything in your code that would tell it to become visible.  All you do is set the element of the drilled array relative to that position 19/19 to true.  That will not affect any object.  You have to target the object in and set its _alpha to be true.

Pippa01Author
Inspiring
June 13, 2013

Thanks for your reply.

Ned Murphy wrote:

THe only reason I can see why the last would not react to being rolled over would be due to something blocking it.  If I run your code I can roll over the object and have its alpha change.

Sorry, that was my mistake. There was an invisible object blocking the circle. Thanks for pointing it out!

As far as the filled version not appearing, I do not see anything in your code that would tell it to become visible.  All you do is set the element of the drilled array relative to that position 19/19 to true.  That will not affect any object.  You have to target the object in and set its _alpha to be true.

I thought that I had told it to be visible. See snippet of the code below, which occurs immediately after where the filled circles are first created:-

          //filled circles initially invisible

currentCol2=(current2._x-leftMargin)/(spacing + current2._width);

currentRow2=(current2._y-topMargin)/(spacing + current2._height);

if (drilled[currentCol,currentRow]==true){

     current2._alpha = 100;   

}else{

     current2._alpha=0;

                                                            }

Obviously the 'drilled' variable will normally be false until one of the grid points has been clicked, but I have tried to test this conditional visibility by setting drilled[10,10] to true before I create the circles.  It doesn't have any effect, so I guess that I'm not giving Flash the correct information to equate the current version of the circle with the corresponding element in the 'drilled' array.

Thanks for all of your help.

Ned Murphy
Legend
June 13, 2013

Here is the only code I see that involves clicking one of the open circles...

          current.onRelease=function(){

                    drilled[currentCol,currentRow]=true;

                    trace(drilled[currentCol,currentRow]);

                    this.removeMovieClip();

          }

All that it does is set the drilled array value for one of its elements to be true.  The other code you show is only executed at the start as far as I can see, so it sets it to whatever value it is at the start.

You need to target the specific filledCircle object in that code and set its _alpha property to 100.  Since your currentCol and currentRow values are one less than the values for the names of the objects that you assign, you need to adjust them up to target the object

          current.onRelease=function(){

                    drilled[currentCol,currentRow]=true;

                    _root["filledCircle_mc"+String(currentCol+1)+"_"+String(currentRow+1)]._alpha = 100;

                    this.removeMovieClip();

          }