We have introduced our custom ImageLoader class in a previous tutorial: Loading Images and Spinning them in 3D in Terms of Custom AS3 Classes, so we only list below the class's public properties and methods. In essence, the class loads concurrently any number of image files at runtime. The class extends the EventDispatcher class. It dispatches two custom events: one when all images have successfully loaded, and the other in the case of a loading error.
The ImageLoader class has two public static constants. 'static' means the contants are the same for every instance of the class. The constants correspond to the two custom events:
- IMGS_LOADED:String = "imgsLoaded"
- LOAD_ERROR:String = "loadError"
The ImageLoader class has one public, read-only property:
- bitmapsArray This is the array of bitmaps corresponding to loaded images. The array is populated after the method 'loadImgs' has run and images have loaded without an error.
The ImageLoader class has the following public methods:
- The constructor evoked with the key word 'new': new ImageLoader()
The class constructor takes no parameters. It only initializes a few variables; the main work is performed by
the 'loadImgs' method.
- loadImgs(imgsFiles:Array):void The method takes an array of strings as a parameter. The strings represent URLs of the image files to be loaded. Once called, the event listeners set by the method trigger LOAD_ERROR event in case of an error. Otherwise, they trigger IMGS_LOADED event when all the images are loaded. When the event IMGS_LOADED is dispatched, the public, read-only property bitmapArray is populated with bitmap objects corresponding to loaded images. 'loadImgs' method can be called again on the same instance of ImageLoader but only after the previous call to the method concluded successfully. (If called before IMGS_LOADED event is dispatched for the prior call, the method does nothing.)
- Download all 'fla', 'as', and 'jpg' files corresponding to this tutorial: menu3d.zip
We hope you find this tutorial useful and create your own spectacular 3D menus!