Your browser does not support iframes.
Here is an example on how to use Bulkloader to upload multiple photos.
Thanks to wasted potential and the bulkloader AS3 classes for this example. I have a link to the complete code, minus the FLA, the photos, and the bulkloader classes, which you should download from the google code site to ensure that you have the latest version:
A step-by-step explanation
The example below puts all the photos into a folder called “photos” and stores this information in a Vector. A Vector is just a strictly-typed array (meaning, if you make a Vector that contains say, integers, that every item you put in the Vector should be an integer or you will get an annoying “out-of-range” error).
To create a new Vector, you can use the format:
private var photos:Vector.= new Vector.
To add items to a Vector, you can write vectorName.push:
photos.push("photos/400px-2008-08-22_Skateboarder_floating_in_the_air.jpg")
Or use the syntax below:
photos[0] = "photos/400px-2008-08-22_Skateboarder_floating_in_the_air.jpg"; photos[1] = "photos/800px-Canal_St._Skateboarders_2.jpg"; photos[2] = "photos/Eiseisugimoto.jpg"; photos[3] = "photos/Retrato-jura1.jpg"; photos[4] = "photos/Skateboarder_grinding_public_bench_2005.jpg";
Use your own photos. I just grabbed some images from the Wiki Commons.
To make this work, create a .fla file and name it Main.fla. Then give the Document Class a name of BulkLoaderMultiplePhoto.
In my constructor function, I tend to try to check to see if the stage is initialized before I go on to do anything else. It’s a bit of extra writing but it saves your weird headaches later (from loading, trying to access objects on the stage, all sorts of stuff.)
public function BulkLoaderMultiplePhoto ():void
{
if (stage) init();
else addEventListener(Event.ADDED_TO_STAGE, init);
}
private function init(e:Event = null):void
{
removeEventListener(Event.ADDED_TO_STAGE, init);
// do your stuff here
I use a loop to loop through the “photos” Vector:
for (var i:int = 0; i < photos.length; i++) {
// use a loop to "add" each photo to the loader with a unique id
bulkLoader.add(photos[i], { id:"photo-"+i, priority:10 - i} );
bulkLoader.get("photo-"+i).addEventListener(BulkLoader.COMPLETE, onPhotoLoaded, false, 0, true);
bulkLoader.get("photo-"+i).addEventListener(BulkLoader.ERROR, onPhotoError, false, 0, true);
The loop starts off at i=0
(var i:int = 0;
- and then increments
i++)
- each time until it reaches the maximum, which is set for the amount of photos (photos.length gives the "size" or the amount of the photos in the photos Vector)
Keep in mind that I started at photos[0] so I have to set the maximum to 1 just below the photos.length (i < photos.length). In this case, I have five (5) photos in the example, and the last photo is at photos[4], which, as you can see is less than (i <) photos.length (5, for 5 photos).
At any rate, that's a pretty quick explanation of what a loop does but onto the Bulkloader explanation.
