8 Replies Latest reply on Nov 27, 2013 8:29 AM by DMB89

    Problems with converting array value into movieclip name

    DMB89

      Hi everyone. Im quite new to flash and especially arrays so here is my dilema that i hope someone can advise me on:

       

      the below code is what i have come up with from previous advice / dissusions but doesnt work. plus i dont fully understand it so it could be something silly and simple.

       

      /////////////////////////////////////////

       

      stop();

       

      var caseStudy = new Array(c1, c2, c3, c4, c5, c6);

       

      for (var i = 1; i < caseStudy.length; i++)

      {

          caseStudy[i].ivar = i;

         

          trace(p1_caseStudyMenu[caseStudy[this.ivar]._name]);                                        //currently traces : undefined

          trace("caseStudy" + i);                                                                                            //currently traces : caseStudy1 caseStudy2 caseStudy3 etc.

         

          //currently none of the below works, not being accessed / called correctly

       

          p1_caseStudyMenu[caseStudy[this.ivar]._name].onRollOver = function()                 

          {

              this.gotoAndPlay(2);

          }

          p1_caseStudyMenu[caseStudy[this.ivar]._name].onRollOut = function()

          {

              this.gotoAndPlay(1);

          }

          p1_caseStudyMenu[caseStudy[this.ivar]._name].onRelease = function()

          {

              gotoAndStop(caseStudy[this.ivar]);

          }

      }

        • 1. Re: Problems with converting array value into movieclip name
          DMB89 Level 1

          after alot of teddious trial and error I have now managed t oget to here and the only thing i cannot do now is get the onRelease function to work

           

           

          /////////////////////////////////////////////////////////

           

          stop();

           

          var myCaseStudy:Array = new Array("c1", "c2", "c3", "c4", "c5", "c6");

           

          for (var i = 0; i < myCaseStudy.length; i++)

          {   

              myCaseStudy[i].ivar = i;

             

              trace(myCaseStudy[i]);

             

              p1_caseStudyMenu[myCaseStudy[i]].onRollOver = function()

              {

                  this.gotoAndPlay(2);

              }

              p1_caseStudyMenu[myCaseStudy[i]].onRollOut = function()

              {

                  this.gotoAndPlay(1);

              }

              p1_caseStudyMenu[myCaseStudy[i]].onRelease = function()

              {

                  //gotoAndStop(myCaseStudy[i]);

                  trace(this[myCaseStudy[i]]);  //currently traces : undefined

              }

          }

          • 2. Re: Problems with converting array value into movieclip name
            Ned Murphy Adobe Community Professional & MVP

            The value of i by the time you click anything is likely 1 greater than the number of values in the array, so it is trying to access a value in the array that doesn't exist.  You could confirm this by havng the for loop go to one less than it currently does and you'll likely see "c6" output.

             

            You might get better result if you use that ivar you created but don't yet use because it will hold the value assigned to it when the loop was running.

            • 3. Re: Problems with converting array value into movieclip name
              DMB89 Level 1

              stop();

               

              var myCaseStudy:Array = new Array("c1", "c2", "c3", "c4", "c5", "c6");

               

              for (var i = 0; i < myCaseStudy.length; i++)

              {   

                  myCaseStudy[i].ivar = i;

               

                  trace(myCaseStudy[i]);

               

                  p1_caseStudyMenu[myCaseStudy[i]].onRollOver = function()

                  {

                      this.gotoAndPlay(2);

                  }

                  p1_caseStudyMenu[myCaseStudy[i]].onRollOut = function()

                  {

                      this.gotoAndPlay(1);

                  }

                  p1_caseStudyMenu[myCaseStudy[i]].onRelease = function()

                  {

                      trace(i);            // 6

                      trace("c"+i);        // c6

                      trace(this[ivar]);  // undefined

               

                      //gotoAndStop("c1");

                      //gotoAndStop("c2");   

                      //gotoAndStop("c3");   

                      //gotoAndStop("c4");   

                      //gotoAndStop("c5");   

                      //gotoAndStop("c6");   

                      // this is where i need to be going depending on the button clicked. however i seem to always be tracing c6 no matter what button is clicked.

                  }

              }

              • 4. Re: Problems with converting array value into movieclip name
                DMB89 Level 1

                I am so close yet so far...All i am trying to do is use this code below with arrays to compensate for all 6 results rather than writting it 6 times manaully.

                 

                p1_caseStudyMenu.c1.onRelease = function()

                    {

                        gotoAndPlay("c1");

                        p1_caseStudyMenu.c1.gotoAndStop(1);

                        p1_caseStudyMenu.c1.enabled = false;

                    }

                • 5. Re: Problems with converting array value into movieclip name
                  Ned Murphy Adobe Community Professional & MVP

                  Your traces are only confirming what I already told you...the value of i by the time you click anything is one greater than the last index of the array... there is no myCaseStudy[6], just 0 thru 5.

                   

                  What you should trace in that function is "this" (without quotes) to see what 'this' targets.  It needs to be the object that you assigned the ivar to, otherwise you will get an undefined result.

                  • 6. Re: Problems with converting array value into movieclip name
                    DMB89 Level 1

                    trading "this" gives _level0.p1.p1_caseStudyMenu.c1 but i dont see how thats helping...sorry im being stupid here....its all way over my head but i dont want to chicken out and do it the amature way

                    • 7. Re: Problems with converting array value into movieclip name
                      Ned Murphy Adobe Community Professional & MVP

                      If that is tracing the object you expect it to be, then that's helping by telling you that.

                       

                      I mentioned earlier that you should be using that ivar value that you assign, but there is one big problem with the way you assign it.  You are assigning it to a string in an array...

                       

                           myCaseStudy[i].ivar = i;

                       

                      which won't do anything for you.  What you need to be doing is assiging that ivar to the object represented by that string, just like you do for the various mouse interactive coding.

                       

                           p1_caseStudyMenu[myCaseStudy[i]].ivar = i;

                      • 8. Re: Problems with converting array value into movieclip name
                        DMB89 Level 1

                        PERFECT! i new it was my lack of understanding of string conveting