coverflow

animated 3D interface to flip though images.

coverflow

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="0x000000")]	
	
	public class main extends Sprite {
		
		private var fps				:FlashFPS;
		private var av				:audioVisualizer;
		private var theCoverflow	:coverflow;
		private var lbl				:TextField
		private var i 				:Number;
		private var loader			:URLLoader;
		private var bulk			:BulkLoader;
		private var albums			:XMLList;
		private var albumArt		:Array;
		
		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("playlist.xml"));
			
			addEventListener(Event.ENTER_FRAME, loop);
		}
		private function err(e:Event):void {
			lbl.textColor = 0x660000;
			lbl.htmlText = "<font face=\"verdana\" size=\"10\">error loading playlist</font>";		
		} 		
		private function loaded(e:Event):void {
			lbl.text = 'loaded';
			loader = URLLoader(e.target);
			//you must remember to unescape the data!
			var thexml:XML = new XML(unescape(loader.data));
			albums = thexml.descendants("album");
			
			bulk = new BulkLoader("mp3");
			
			i = 0;
			while(i++ < albums.length()) {
				bulk.add(albums[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 {
			lbl.textColor = 0x660000;
			lbl.htmlText = "<font face=\"verdana\" size=\"10\">ERROR</font>\n<font face=\"verdana\" size=\"5\">failed loading images.</font>";
		}
		private function loading(e:BulkProgressEvent):void {
			lbl.htmlText = "<font face=\"verdana\" size=\"10\">loading images: " + e.itemsLoaded + " of " + e.itemsTotal + "</font>";	
		}
		private function imgsloaded(e:BulkProgressEvent):void {
			lbl.htmlText = "";
			albumArt = new Array({img:Bitmap});
			i = 0;
			while(i++ < albums.length()) {
				albumArt[i-1] = {img:BitmapData(BulkLoader.getLoader("mp3").getBitmapData(albums[i-1].img))};
			}
			//create audio visualizer
			av = new audioVisualizer();
			av.y -= 100;
			addChild(av);
			
			//create coverflow						
			theCoverflow = new coverflow(albums, albumArt, stage);
			addChild(theCoverflow);
			
			//create debug
			fps = new FlashFPS(0x006600, 0x000000, 0xffffff, 0, "kb");
			addChild(fps);
		}
		private function loop(e:Event):void {
			if(fps != null) {
				fps.update("rendered: " + (theCoverflow.stats.triangles + av.stats.shadedTriangles) + " triangles");
			}
		}
	}
}

Download

raw zip tar