一个相册效果

package {
	import flash.display.MovieClip;
	import flash.display.Loader;
	import flash.display.Shape;
	
	import flash.events.MouseEvent;
	import flash.events.Event;
	import flash.net.URLRequest;
	import fl.events.ListEvent;
	
	
	import fl.data.DataProvider;
	
	import fl.controls.ScrollBarDirection;
	import fl.controls.listClasses.ImageCell;
       /*   
     *author :SinSoul 
     *blogs: http://www.cnblogs.com/sinsoul                                    
     */	
	public class Main extends MovieClip {
		var xml:XML;
		var loader:Loader;
		var dp:DataProvider;
		var shape:Shape;
		var shape1:Shape;
		public function Main():void {

			init();

		}
		private function init():void {
			xml=
			<root>
			<image smallImg="images/1.png" bigImg="images/1.jpg"/>
			<image smallImg="images/2.png" bigImg="images/2.jpg"/>
			<image smallImg="images/3.png" bigImg="images/3.jpg"/>
			<image smallImg="images/4.png" bigImg="images/4.jpg"/>
			<image smallImg="images/5.png" bigImg="images/5.jpg"/>
			<image smallImg="images/6.png" bigImg="images/6.jpg"/>
			<image smallImg="images/7.png" bigImg="images/7.jpg"/>
			<image smallImg="images/8.png" bigImg="images/8.jpg"/>
			<image smallImg="images/9.png" bigImg="images/9.jpg"/>
			<image smallImg="images/10.png" bigImg="images/10.jpg"/>
			<image smallImg="images/11.png" bigImg="images/11.jpg"/>
			<image smallImg="images/12.png" bigImg="images/12.jpg"/>
			<image smallImg="images/13.png" bigImg="images/13.jpg"/>
			<image smallImg="images/14.png" bigImg="images/14.jpg"/>
			<image smallImg="images/15.png" bigImg="images/15.jpg"/>
			<image smallImg="images/16.png" bigImg="images/16.jpg"/>
			<image smallImg="images/17.png" bigImg="images/17.jpg"/>
			<image smallImg="images/18.png" bigImg="images/18.jpg"/>
			<image smallImg="images/19.png" bigImg="images/19.jpg"/>
			<image smallImg="images/20.png" bigImg="images/20.jpg"/>
			<image smallImg="images/21.png" bigImg="images/21.jpg"/>
			</root>;

			dp=new DataProvider(xml);

			Tlist.dataProvider=dp;
			Tlist.labelField='bigImg';
			Tlist.sourceField="smallImg";
			Tlist.width=100;
			Tlist.height=350;
			Tlist.rowHeight=80;
			Tlist.columnWidth=80;
			Tlist.direction=ScrollBarDirection.VERTICAL;
			shape=new Shape();
			shape.graphics.lineStyle(3,0x454545,1);
			shape.graphics.beginFill(0xffffff);
			shape.graphics.drawRect(270,100,200,200);
			shape.graphics.endFill();
			addChild(shape);
			shape1=new Shape();
			shape1.graphics.lineStyle(3,0x454545,0.7);
			shape1.graphics.beginFill(0xffffff);
			shape1.graphics.drawRect(280,110,180,180);
			shape1.graphics.endFill();
			addChild(shape1);
			Tlist.addEventListener(MouseEvent.CLICK,onclick);
			Tlist.addEventListener(ListEvent.ITEM_CLICK,onclick2);

		}
		private function drawRect(mc:MovieClip):void {

			mc.graphics.beginFill(Math.random()*0xffffff);
			mc.graphics.drawRect(0,0,400,400);
			mc.graphics.endFill();
		}

		private function onclick(e) {

			trace(ImageCell(e.target).label);
		}



		private function onclick2(e) {

			loader=new Loader();
			loader.load(new URLRequest(Tlist.itemToLabel(e.item)));
			loader.contentLoaderInfo.addEventListener(Event.COMPLETE,com);
		}

		private function com(e:Event) {
			var a:Number=loader.width;
			var b:Number=loader.height;

			if (loader.width>loader.height) {
				loader.width=200;
				loader.height=200/a*loader.height;
				loader.addEventListener(Event.ENTER_FRAME,ok);
				function ok(e:Event) {
					e.target.x+=(((200-loader.width)/2+270)-loader.x)/12;
					e.target.y+=(((200-loader.height)/2+100)-loader.y)/12;
					e.target.alpha-=(1-0.2)/200;
					if (e.target.x>=((200-loader.width)/2+270-0.05)&&e.target.y>=((200-loader.height)/2+100-0.05)) {
						e.target.removeEventListener(Event.ENTER_FRAME,ok);
						e.target.alpha=0;
					}
				}

			} else if (loader.height>loader.width) {
				loader.height=200;
				loader.width=200/b*loader.width;
				loader.addEventListener(Event.ENTER_FRAME,ok2);
				function ok2(e:Event) {
					e.target.x+=(((200-loader.width)/2+270)-loader.x)/12;
					e.target.y+=(((200-loader.height)/2+100)-loader.y)/12;
					e.target.alpha-=(1-0.2)/200;
					if (e.target.x>=((200-loader.width)/2+270-0.05)&&e.target.y>=((200-loader.height)/2+100-0.05)) {
						e.target.removeEventListener(Event.ENTER_FRAME,ok2);
						e.target.alpha=0;
					}
				}

			}
			addChild(loader);
		}



	}
}

posted @ 2010-11-07 21:27  sinsoul  阅读(455)  评论(0编辑  收藏  举报