Loader vs. URLLoader in ActionScript 3

This short tutorial is written in response to a question from one of our visitors: "How can you load a random image from a list of images specified in an external XML file?" The question presents an opportunity to show a simple example that illustrates the difference between Loader and URLLoader classes. According to Flash documentation, the former class is for swf and image formats (gif, jpg, and png) while the latter is for text and binary data. Hence, we will use URLLoader to open an XML file that contains a list of names (URLs, technically) of image file, and then use a Loader to load an image from the list.

Refresh your browser window to see a randomly chosen image from a list of four images (by Jess Ensley) whose names are specified in an external xml file

The first page of the tutorial presents commented code to accomplish the effect shown above. The second page shows how to randomize the list of images for a different effect.


Download the file randompic.zip to get all source files and sample images for this tutorial.

Back to Basic Tutorials              Back to Flash and Math Home

We welcome your comments, suggestions, and contributions. Click the Contact Us link below and email one of us.

Adobe®, Flash®, ActionScript®, Flex® are registered trademarks of Adobe Systems Incorporated.