10 Replies Latest reply on Jun 18, 2013 1:24 PM by Pippa01

    Problems with an array (attachMovie)

    Pippa01 Level 1

      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

      Screen shot 2013-06-13 at 12.13.14.png

        • 1. Re: Problems with an array (attachMovie)
          Ned Murphy Adobe Community Professional & MVP

          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.

          • 2. Re: Problems with an array (attachMovie)
            Pippa01 Level 1

            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.

            • 3. Re: Problems with an array (attachMovie)
              Ned Murphy Adobe Community Professional & MVP

              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();

                        }

              1 person found this helpful
              • 4. Re: Problems with an array (attachMovie)
                Pippa01 Level 1

                Thanks. It works very well, so much appreciated! I won't be able to get back to this again now for a couple of days, so will have a good look at your code then to see how it works. It's proving to be a big learning curve, so it's very good to have your help.

                 

                What I will need to do though, is to go into the next frame to carry out the animation for the drilling operation, as I'll need all the variables set in the current frame to carry through into the next frame? Then, I'll need to go back into the current frame to identify more drilling sites. Will the filledCircles that have been clicked still be present.

                 

                Many thanks.

                • 5. Re: Problems with an array (attachMovie)
                  Ned Murphy Adobe Community Professional & MVP

                  THe code line that I offered uses what is known as bracket or array notation.  What that does is allows you to use string values to target objects.  What you will find inside the brackets is just building the name of the filledCircle object you created and assigned the name to.

                   

                  If you extend the layer across the frames you should be able to use the same variables and the circles should still exist.  If you create a new keyframe you could lose things, so just go into the layer you wish to extend and select the frame you want to extend to and right click it and choose Insert Frame.  That should cause the nearest keyframe preceding it to extend to that frame.

                  1 person found this helpful
                  • 6. Re: Problems with an array (attachMovie)
                    Pippa01 Level 1

                    Thanks for the explanation. That was very helpful.

                     

                    However, I am having problems with the variables. I did as you suggested though and extended the (grid) layer, but had to create a separate keyframe for the code layer, as that code had to execute first before moving into the next frame. See below (I've also attached the fla, but if you need any more information, please let me know):

                     

                    In frame 2 of the animation, if an open circle mc is clicked, that mc is deactivated (removed), drilled becomes true for that coordinate, a filled circle becomes visible in its place and you enter another frame(3) (this is currently just a test frame), to later be used to implement the drilling animation for a clicked coordinate.

                     

                    It all seems to be working as it should, until the open circle is clicked and you enter frame 3. See below:

                     

                    • All the instances of the openCircle mc's are still active in frame 3, so I guess I need to use removeMovieClip(). I know how to do that for a single instance, but howdo I execute that if they're in an array?
                    • I also don't want any instances of the filledCircles from frame 2 to be visible in frame 3. I'm not sure how to hide them temporarily in frame 3 and then have them visible again in frame 2?
                    • When I go back to frame 2 (using a back button), all of the filled circles in the array are visible, whereas only the ones that have been previously clicked (drilled = true) should be visible. However, when I return to frame 2 and do a trace to find out which coordinates are set to true/false, it seems that a whole row is now set to (drilled = true), whereas it should just be a single coordinate set to true. Oddly enough, the variable seems to working properly in frame 2 when the code is first executed, but then when I go to frame 3 and then re enter frame 2, it's not working as it should do. Below is the trace code that I've used:

                     

                    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]);

                                                  }

                     

                    If you could help, I'd be very grateful! Very many thanks.

                     

                    http://synergese.co.uk/boreholes15.fla

                     

                    Message was edited by: Pippa01 Sorry, Although the original question was correct, I've just unmarked it as correct. Maybe, I should have started it as a new thread?

                    • 7. Re: Problems with an array (attachMovie)
                      Ned Murphy Adobe Community Professional & MVP

                      It looks like you are trying to get me or someone to do the design work for you.  All of what you describe having a problem with should be within your ability to do without looking for help.

                       

                      If you have an array then you just loop thru the array and process each element of it, one at a time.  IF you need to make a number of things visible/invisible, loop thru them and process them.

                       

                      Whenever you have new problems you are trying to solve you should start a new posting.  If the problem that started the thread is answered, you should mark the thread as answered.  If other answers were helpful, then you should mark them accordingly.

                      1 person found this helpful
                      • 8. Re: Problems with an array (attachMovie)
                        Pippa01 Level 1

                        I'm extremely sorry and believe me, it was never my intention to get someone else to do the design/coding work for me. I was experiencing genuine difficulties. Usually, I manage to execute reasonable, though imperfect code. This time, I was trying to get it right, though I feel that maybe I should have gone for a less ambitious project.

                         

                        However, I must say that I've learnt a lot from you and I hope that others have benefitted as well.

                         

                        Many thanks again.

                        • 9. Re: Problems with an array (attachMovie)
                          Ned Murphy Adobe Community Professional & MVP

                          You're welcome, and there's no need to apologize.  I know it can be overwhelming at times.  Sometimes the easiest way to really figure out a solution is to put yourself in the process and imagine what steps you would have to take to accomplish process things.  Then turn that process into code to let the program do it instead.  The good thing about the code doing the work is that it can do complex and repetitive things in the blink of an eye.  So while the whole process might seem like alot of work from your persepective, the program thrives on it.

                          • 10. Re: Problems with an array (attachMovie)
                            Pippa01 Level 1

                            I did figure it out in the end - I didn't understand how Flash handled 2 dimensional arrays, so I implemented a one dimensional array instead and that works. Now onto the next stage! Thanks.