O'Reilly logo

Essential ActionScript 3.0 by Colin Moock

Stay ahead with the world's most comprehensive technology and business learning platform.

With Safari, you learn the way you learn best. Get unlimited access to videos, live online training, learning paths, books, tutorials, and more.

Start Free Trial

No credit card required

Using Dynamic Instance Variables to Create Lookup Tables

A lookup table is a data structure that maps a set of names to a corresponding set of values. For example, the following pseudocode shows a lookup table representing the courses of a meal:

appetizer:  tortilla chips
maincourse: bean burrito
dessert:    cake

To represent the lookup table using dynamic instance variables, we would use the following code:

var meal:Object = new Object();
meal.appetizer  = "tortilla chips";
meal.maincourse = "bean burrito";
meal.dessert    = "cake";

Now let's consider a more involved scenario. Imagine an inventory application for a bookstore in which the user can browse books by ISBN number. Information for each book is loaded from an external server. To minimize communication with the server, the application loads the information for 500 books at a time. For the sake of simplicity, we'll assume that each book's information takes the form of a single string, in the following format:

"Price: $19.99. Title: Path of the Paddle"

To store the loaded book information in ActionScript, we create an instance of the Object class, which will act as a lookup table for the books:

var bookList:Object =  new Object();

As each book's information is loaded, we assign it to a new dynamic instance variable of the preceding bookList object. Each variable's name corresponds to a book's ISBN number, preceded by the string "isbn". For example, the variable for a book with the ISBN number 155209328X would be named isbn155209328X. The ...

With Safari, you learn the way you learn best. Get unlimited access to videos, live online training, learning paths, books, interactive tutorials, and more.

Start Free Trial

No credit card required