4 Replies Latest reply on May 12, 2013 11:04 AM by LarkspurLane

    How do I access an array element?

    LarkspurLane

      I am trying to access an array element on a button click.  In creation complete I put this: var students = ["Theo Arguna","Leif Arneson","John Egan","Sakura Nakahara","Rebecca Pilkington","Debra Sutter"];

       

      on the button mouseover i put this: 

      var myVariable = sym.getVariable("students.eq[0]");

       

       

      sym.getSymbol("message").$("Text4").html("Click now to see " + sym.getVariable("myVariable") + "'s work.");

       

      When i test I get the word "undefined" where "myVariable" is in the above line of code.

       

      Any suggestions on how to get the array element into this?

        • 1. Re: How do I access an array element?
          LeandroAmano

          Hi!

           

          var students = ["Theo Arguna","Leif Arneson","John Egan","Sakura Nakahara","Rebecca Pilkington","Debra Sutter"];

          //first set your variable

          sym.setVariable("myVariable", students[0]);

          sym.getSymbol("message").$("Text4").html("Click now to see " + sym.getVariable("myVariable") + "'s work.");

           

          att

          Leandro Amano

          • 2. Re: How do I access an array element?
            LarkspurLane Level 1

            Thanks for looking at this.

             

            I tried your reply and assumed you meant to put this on the mouseOver

             

            //first set your variable

            sym.setVariable("myVariable", students[0]);

            sym.getSymbol("message").$("Text4").html("Click now to see " + sym.getVariable("myVariable") + "'s work.");

             

            I tried that and now I don't get anything on mouseOver, whereas before, I got the "undefined" message.

            • 3. Re: How do I access an array element?
              jbowden Adobe Employee

              Hi there,

               

              You're almost there...

               

              Put this in your creationComplete event:

               

              // sets variable students to the array

              sym.setVariable("students", ["Theo Arguna","Leif Arneson","John Egan","Sakura Nakahara","Rebecca Pilkington","Debra Sutter"]);

               

              And put this in your button mouseover event:

               

              // get the array element that you want

              var myVariable = sym.getVariable("students")[0];

              sym.getSymbol("message").$("Text4").html("Click now to see " + myVariable + "'s work.");

               

              hth,

              Joe

              • 4. Re: How do I access an array element?
                LarkspurLane Level 1

                I had tried the part you suggested in my creationComplete before.

                 

                The part that stumped me was

                 

                var myVariable = sym.getVariable("students")[0];

                 

                What I couldn't find in the documentation was to put the [ ] outside the quotation marks and before the semicolon in getVariable. 

                 

                Thanks