First time here? First time here? Newsletter Signup Newsletter
Search tutorials
Author: Helen Triolo | Website: http://www.i-technica.com

Actionscript Primer (con't)

Using associative arrays to address objects

One other way of addressing objects in Flash 5 needs to be noted before proceeding. It allows us to get rid of the need for "eval" as it was used in Flash 4 to evaluate the name of a variable. (Eval in Flash 5 is not the same as the javascript eval. It still functions the same as it did in Flash 4, to evaluate variable names made up of concatenated strings, but is only needed in rare situations like finding the address of a droptarget or when creating a new object that takes a movieclip specified in a variable as its argument).

Every object in Flash 5 has its own built-in array, which is a pointer to all of the objects it contains. This array, and thus, the object pointed to, may be addressed by using the object's name as the array name, and the string name of the object to be addressed as the array index. A simple case would be

_root["mcTarget"], which is equivalent to _root.mcTarget
Note: that the array pointer is a string and there is no dot between the name of the array and its index.

This method of addressing objects becomes important whenever the object to be addressed (a movieclip, in particular) is referred to with a variable, or a concatenation of variables, rather than with an instance name. For example, if a movieclip (mcMain) on the main timeline is duplicated several times in a loop (mcNew1, mcNew2, .. mcNew45), and then the user wishes to set the alpha of all movieclips to 50%, this mode of address comes in handy:

for (i=1; i <= 45; i++) {
_root["mcNew"+i]._alpha = 50;

There is no way this could be accomplished with dot syntax (unless eval is used; but array syntax is a much cleaner way to set up the code).

OK, now that we've noted how both dot syntax and associative array syntax work, on to set up the symbols we need in our Flash movie.

» Level Advanced

Added: 2000-12-15
Rating: 7 Votes: 79
(10 being the highest)
» Author
Helen Triolo started i-Technica, a web design shop in the Washington DC area, three years ago, after being an apps engineer for a Silicon Valley company and then a programmer for an uncountable number of years. She's been hooked on Flash since buying a copy last January.
» Download
Download the files used in this tutorial.
» Forums
More help? Search our boards for quick answers!


  • There are no comments yet. Be the first to comment!

  • You must have javascript enabled in order to post comments.

Leave a Comment
  • Your email address will not be published. All fields are required.
Featured Flash FLA
» Author: Inocreato
» Title: RaiseTheBlocks
» Description: Raise all the blocks to win the game
Featured Sound Loops
Image for equalize

Audio Player

» Author: TomCat Carty
» Title: The Wood
» Description: Just a little game ending or it can maybe be looped. Recorders with music box and percussion to give the feel of well, I don't know, the woods? Free to use, just credit me. thank you
Latest Font
» Author: Fábio FAFERS
» Description: I created this font for free use. Everyone can apply it in personal or business texts. Its free, but I want to be communicated in case of business use. Donations are accepted to keep the project of free fonts alive! Thank you all
Featured Sound Fx
Image for equalize

Audio Player

» Author: Davisigner
» Description: Hmm... what to say about this one? It's reminiscent of the closing notes of the opening music from the Three Stooges done in a church organ style with a closing cymbal crash. I'll give this one away gratis, but feel free to check out my free loops and potential upcoming license-mandated ones over in the respective part of Flashkit.