Skip navigation
Currently Being Moderated

accessing an array

Jul 27, 2012 5:48 PM

_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.

 
Replies
  • Currently Being Moderated
    Jul 27, 2012 6:25 PM   in reply to codeBeastAdobe

    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.

     
    |
    Mark as:
  • Currently Being Moderated
    Jul 27, 2012 6:54 PM   in reply to codeBeastAdobe

    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

     
    |
    Mark as:
  • Currently Being Moderated
    Jul 28, 2012 4:29 AM   in reply to codeBeastAdobe

    You're welcome

     
    |
    Mark as:

More Like This

  • Retrieving data ...

Bookmarked By (0)

Answers + Points = Status

  • 10 points awarded for Correct Answers
  • 5 points awarded for Helpful Answers
  • 10,000+ points
  • 1,001-10,000 points
  • 501-1,000 points
  • 5-500 points