Saturday, December 29, 2007

Do you use the LoaderContext class?

Last night I spent several grueling hours trying to track down a bug in an Flash ActionScript 3 program I'm writing. I was getting an error when I would try to call a static method when the movie is loaded into another movie. I wouldn't get the error when I play the movie itself. The error was that the class name is an undeclared variable. Finally, I found a post on that led me to the answer.

The problem was relying on the default LoaderContext parameter to the Loader.load() method. You may not be familiar with this parameter, but it is important in how the Flash Player deals with an additional application being loaded in and how it prevents possible name collisions (see the thread I linked to above).

After solving the problem, I decided to look further into the books I have. Out of six books I looked in, all of them mentioned the Loader class but only one mentioned LoaderContext. Ironically, that was the last one I looked in because it is a Flex book, Programming Flex 2. It has a good explanation of the issues.