Carousel

A circular flash animated 3D interface

Carousel

src/main.as


package {
	import br.com.stimuli.loading.*;
	
	import flash.display.*;
	import flash.events.*;
	import flash.net.*;
	import flash.text.*;
	
	import nu.xero.flash.*;
	import nu.xero.gui.*;
	
	[SWF(backgroundColor="0x333333")]	
	
	public class main extends Sprite {
		private var lbl:TextField;
		private var loader			:URLLoader;
		private var bulk			:BulkLoader;
		private var gallery			:XMLList;
		private var images			:Array;
		private var i				:Number;
		private var wheel			:carousel;
		private var fps				:FlashFPS;
		
		public function main() {
			stage.scaleMode = StageScaleMode.NO_SCALE;
			stage.align = StageAlign.TOP_LEFT;
			stage.quality = StageQuality.MEDIUM;
			stage.frameRate = 100;
			
			lbl = new TextField();
			lbl.autoSize = TextFieldAutoSize.CENTER;
			lbl.multiline = true;
			lbl.textColor = 0xffffff;
			lbl.selectable = false;
			lbl.scaleX = lbl.scaleY = 2;
			lbl.x = 400; 
			lbl.y = 200;
			this.addChild(lbl);
			
			loader = new URLLoader();
			loader.addEventListener(IOErrorEvent.IO_ERROR, err);
			loader.addEventListener(Event.COMPLETE, loaded);
			loader.load(new URLRequest("gallery.xml"));
			
			addEventListener(Event.ENTER_FRAME, loop);
		}
		private function msg(txt:String, color:uint = 0xffffff):void {
			lbl.textColor = color;
			lbl.htmlText = "<font face=\"verdana\" size=\"10\">"+txt+"</font>";
		}
		private function err(e:Event):void {
			msg("error loading gallery", 0xff0000);	
		}
		private function loaded(e:Event):void {
			msg("gallery loaded");
			loader = URLLoader(e.target);
			//you must remember to unescape the data!
			var thexml:XML = new XML(unescape(loader.data));
			gallery = thexml.descendants("image");
			bulk = new BulkLoader("hawaii");
			
			i = 0;
			while(i++ < gallery.length()) {
				bulk.add(gallery[i-1].img.toString());
			}
			
			bulk.addEventListener(BulkLoader.PROGRESS, loading);
			bulk.addEventListener(BulkLoader.COMPLETE, imgsloaded);
			bulk.addEventListener(BulkLoader.ERROR, bulkerr);
			bulk.start();
		}
		private function bulkerr(e:ErrorEvent):void {
			msg("error! failed loading images", 0xff0000);
		}
		private function loading(e:BulkProgressEvent):void {
			msg("loading images: " + e.itemsLoaded + " of " + e.itemsTotal);	
		}
		private function imgsloaded(e:BulkProgressEvent):void {
			lbl.htmlText = "";
			images = new Array({img:Bitmap});
			i = 0;
			while(i++ < gallery.length()) {
				images[i-1] = {img:BitmapData(BulkLoader.getLoader("hawaii").getBitmapData(gallery[i-1].img))};
			}
			msg("");
			
			wheel = new carousel(gallery, images, lbl);
			addChild(wheel);
			
			fps = new FlashFPS(0x006600, 0x000000, 0xffffff, 0, "kb");
			addChild(fps);			
		}
		private function loop(e:Event):void {
			if(fps != null) {
				fps.update("rendered: " + wheel.stats.triangles + " triangles");
			}
		}
	}
}

Download

raw zip tar