4 Replies Latest reply: Jul 28, 2012 4:29 AM by Ned Murphy RSS

    accessing an array

    codeBeastAdobe Community Member

      _definitionsArray[_selectedBubble]["mc"])

       

      Hi, I have this code for an array but why are there sets of square brackets? I thought it was smth like:

      _definitionsArray[_selectedBubble]) where _selectedBubble would be a number ie: the index therefore giving us the value at that point. OR would it be because it an associative array with two types and the second bracket indicates you want the mc.

        • 1. Re: accessing an array
          Ned Murphy MVP

          It is possibly making use of bracket notation to target an object with an instance name "mc" that is a child of whatever object _definitionsArray[_selectedBubble] is.

           

          _definitionsArray[_selectedBubble] could be an associative array or it could be a normal array... it really depends on what _selectableBubble's value is.

          • 2. Re: accessing an array
            Ned Murphy MVP

            I should add that _definitionsArray[_selectedBubble] could also be making use of the bracket notation to target an object, although the use of "Array" in the name causes me to think _definitionsArray is an actual array.

             

            If you aren't familiar with using bracket notation to target objects, what it does for you is allows you to use strings to target objects, which becomes very useful in dynamic applications.

             

            Here is a brief example...  suppose you have an object with an instance name "mc", then suppose you have that as a child of another object with an instance name "container".  One way you are probably familiar with for targeting the "mc" object would be...

             

            container.mc     as in     container.mc.x = 200;

             

            using bracket notation you could also use...

             

            container["mc"]    or

             

            this["container"].mc   or

             

            this["container"]["mc"] 

             

            They all target the same "mc" object

            • 3. Re: accessing an array
              codeBeastAdobe Community Member

              Thank you very much, really helpful

              • 4. Re: accessing an array
                Ned Murphy MVP

                You're welcome