Understanding Macromedia Flash 8 ActionScript 2: Basic Techniques for Creatives

Every application needs to keep track of some amount of information. It may be contact information, a list of current movies, or a host of asteroids and bullets. As explained in Chapter 8, variables act as containers for different types of information. One way to provide storage for application data is to declare the appropriate variables. For example:
<b class="bold">var</b> currentUserID:String;<b class="bold">var</b> numberOfAteroids:Number;
It would even be possible to declare enough variables to hold contact information for a group of individuals. Doing so might look like this:
<b class="bold">var</b> user1Email:String;<b class="bold">var</b> user2Email:String;<b class="bold">var</b> user3Email:String;<b class="bold">var</b> user4Email:String;<b class="bold">var</b> user5Email:String;<b class="bold">var</b> user6Email:String;<b class="bold">var</b> user7Email:String;<b class="bold">var</b> user8Email:String;<b class="bold">var</b> user9Email:String;<b class="bold">var</b> user10Email:String;
In this way, enough memory could easily be allocated for 10 e-mail addresses. The technique could even be used for hundreds or thousands of addresses. But the code would be unmanageable. And accessing the individual addresses would be cumbersome. In the early AS1 days, this technique was actually often used. It worked because variables exist as properties of the timeline on which they are defined. Since properties can be accessed by name using the [ ] operator, it is possible to access the above variables like:
<b class="bold">var</b> id:Number = 6;this["user" + id + "Email"] = "<a class="url"> href="mailto:joe@joe.com">joe@joe.com</a>";trace("Email (" + id + ") = " + this["user" + id + "Email"]);<a name="371"></a><a name="N15877"></a>The output would be:
Email (6) = <a class="url"> href="mailto:joe@joe.com">joe@joe.com</a>
This technique is awkward and the code can easily become confusing. It is also...