• Global community
    • Language:
      • Deutsch
      • English
      • Español
      • Français
      • Português
  • 日本語コミュニティ
    Dedicated community for Japanese speakers
  • 한국 커뮤니티
    Dedicated community for Korean speakers
Exit
0

accessing an array

Participant ,
Jul 27, 2012 Jul 27, 2012

Copy link to clipboard

Copied

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

TOPICS
ActionScript

Views

677

Translate

Translate

Report

Report
Community guidelines
Be kind and respectful, give credit to the original source of content, and search for duplicates before posting. Learn more
community guidelines

correct answers 1 Correct answer

LEGEND , Jul 27, 2012 Jul 27, 2012

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.

Votes

Translate

Translate
LEGEND ,
Jul 27, 2012 Jul 27, 2012

Copy link to clipboard

Copied

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.

Votes

Translate

Translate

Report

Report
Community guidelines
Be kind and respectful, give credit to the original source of content, and search for duplicates before posting. Learn more
community guidelines
LEGEND ,
Jul 27, 2012 Jul 27, 2012

Copy link to clipboard

Copied

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

Votes

Translate

Translate

Report

Report
Community guidelines
Be kind and respectful, give credit to the original source of content, and search for duplicates before posting. Learn more
community guidelines
Participant ,
Jul 28, 2012 Jul 28, 2012

Copy link to clipboard

Copied

Thank you very much, really helpful

Votes

Translate

Translate

Report

Report
Community guidelines
Be kind and respectful, give credit to the original source of content, and search for duplicates before posting. Learn more
community guidelines
LEGEND ,
Jul 28, 2012 Jul 28, 2012

Copy link to clipboard

Copied

LATEST

You're welcome

Votes

Translate

Translate

Report

Report
Community guidelines
Be kind and respectful, give credit to the original source of content, and search for duplicates before posting. Learn more
community guidelines