package { /** * Simple photo example */ import flash.display.MovieClip; import flash.events.Event; import flash.events.MouseEvent; import flash.display.Bitmap; // import the bulkloader classes import br.com.stimuli.loading.*; public class BulkLoaderMultiplePhoto extends MovieClip { private var bulkLoader:BulkLoader; private var bulkLoaderName:String = "main"; // vectors are like arrays, but more strict // in this example everything the the vector "array" // must be a string private var photos:Vector. = new Vector.; private var moveThis:Bitmap; private var container:MovieClip; private var click:Boolean = false; private var clickCounter:int = 1; // make every photo the same size for the example private var imageSize:Number = 400; 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); container = new MovieClip(); addChild(container); // photos thanks to the Wiki Commons 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"; // start a new bulkloader bulkLoader = new BulkLoader("main-site", BulkLoader.LOG_VERBOSE); for (var i:int = 0; i < photos.length; i++) { // use a loop to "add" each photo to the loader with a unique i 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); addEventListener(Event.ENTER_FRAME, moveIt); } // start the loading bulkLoader.start(); } private function onPhotoError(e:Event) { trace("photo load error:" + e.target); } private function onPhotoLoaded(e:Event) { trace("the current photo loaded is..." + e.currentTarget.id); var counter:Array = e.currentTarget.id.split("photo-"); trace("counter[1] is " + counter[1]); // outputs just the "count" of the photo // bulkloader loads each image by the id var image : Bitmap = bulkLoader.getBitmap(e.currentTarget.id); image.width = imageSize; image.height = imageSize; image.x = counter[1]*image.width; //Add the image to the holder container.addChild(image); // do something when you click on the images container.addEventListener(MouseEvent.CLICK, onClick); // add the hand cursor so people know it's clickable container.buttonMode = true // remove the listener for the bulkloader so it doesn't suck up memory e.target.removeEventListener(BulkLoader.COMPLETE, onPhotoLoaded); } private function onClick (e:MouseEvent) { click = true; trace("target was" + e.target) } private function moveIt (e:Event) { if (click == true) { if (container.x > -(clickCounter*imageSize)) { container.x -= 10; } if (container.x == -(clickCounter*imageSize)) { click = false; clickCounter++; } } } } }