您的位置:首页 > 其它

flash绘图API:恋上你的CD

2010-12-08 16:14 197 查看






早上,我无意间碰撞到一个女孩,那时候,她匆匆忙地走了。从她的口袋里面掉下了一本陈旧的书,在哪里我看到她藏在书中的那封陈旧的信和cd。我好奇打开它,一边听着她那张cd,一边看她的写的信,忽然间有一种恋上她的感觉。我深深地被那声音和文字吸引,每次站在校园路上,总是想找到那个女孩,每一分每一秒,我心期盼再次能够看到你那细腻的笔迹和温柔的声音。



而你在哪里?





package 
{
	import flash.display.*;
	import flash.net.*;
	import flash.events.*;
	import flash.filters.*;
	import flash.geom.*;
	public class LoveCD extends Sprite
	{
		private var radius:Number;
		private var _bitmap:Bitmap;
		public static const LOAD_COMPLETE:String="complete";
		public function LoveCD(radius:Number)
		{
			this.radius=radius;
		}		
		//加载图片
		public function loadImage(url:String):void
		{
			var loader:Loader=new Loader();
			loader.contentLoaderInfo.addEventListener(Event.COMPLETE,onLoadComplete);
			loader.load(new URLRequest(url));
		}
		
		//绘制底部
		private function drawBase():void
		{
			var bottomShape:Shape=new Shape();
			bottomShape.x=0;
			bottomShape.y=0;
			addChild(bottomShape);
			bottomShape.graphics.beginFill(0xffffff,0.5);
			bottomShape.graphics.drawCircle(0,0,radius);
			bottomShape.graphics.drawCircle(0,0,radius-2);
			bottomShape.graphics.endFill();			
		}
		
		private function onLoadComplete(event:Event):void
		{
			event.currentTarget.removeEventListener(Event.COMPLETE,onLoadComplete);
			var bitmap:Bitmap=Bitmap(event.currentTarget.content);
			drawBase();	
			this.content=bitmap;	
			this.dispatchEvent(new Event(LoveCD.LOAD_COMPLETE));	     
		}
		
		//设置位图
		public function set content(value:Bitmap):void
		{
			this._bitmap=value;
			
		}
		public function get content():Bitmap
		{
			return this._bitmap;
		}
		
		//绘制CD,radiusA,radiusB,radiusC,由小到大
		public function drawCD(image:Bitmap,radiusA:Number,radiusB:Number,radiusC:Number,offPoint:Point=null,repeat:Boolean=false,smooth:Boolean=false):void
		{
			var maskShape:Shape=new Shape();
			maskShape.x=0;
			maskShape.y=0;
			addChild(maskShape);
			if(offPoint==null)		
			maskShape.graphics.beginBitmapFill(image.bitmapData,null,repeat,smooth);
			else
			maskShape.graphics.beginBitmapFill(image.bitmapData,new Matrix(1,0,0,1,offPoint.x,offPoint.y),repeat,smooth);
			
			maskShape.graphics.drawCircle(0,0,radiusA);
			maskShape.graphics.drawCircle(0,0,radius-2);
			maskShape.graphics.endFill();
			
			var shapeB:Shape=new Shape();
			shapeB.x=0;
			shapeB.y=0;
			addChild(shapeB);
			
			shapeB.graphics.beginFill(0x999999,0.3);
			shapeB.graphics.lineStyle(0,0x999999);
			shapeB.graphics.drawCircle(0,0,radiusB);
			shapeB.graphics.drawCircle(0,0,radiusB+2);
			shapeB.graphics.drawCircle(0,0,radiusC);
			shapeB.graphics.endFill();
			
			shapeB.graphics.lineStyle(0,0xffffff,0.6);
			shapeB.graphics.drawCircle(0,0,radiusC-1);
		}
	}
}






package 
{
	import flash.display.*;
	import flash.net.*;
	import flash.events.*;
	import flash.filters.*;
	import flash.geom.*;
	public class Example extends Sprite
	{
		private var mycd:LoveCD=new LoveCD(200);
		public function Example()
		{
			init();
		}
		private function init():void
		{
			addChildAt(mycd,0);
			mycd.x=stage.stageWidth/2;
			mycd.y=stage.stageHeight/2;
			mycd.filters=[new DropShadowFilter(3,45,0.5,1,1)];
			mycd.loadImage("1.jpg");//加载图片
			mycd.addEventListener(LoveCD.LOAD_COMPLETE,onLoadComplete);
		}
		
		private function onLoadComplete(event:Event):void
		{
			mycd.drawCD(mycd.content,30,50,70,new Point(-350,-230));			 
		}
		 
	}
}
内容来自用户分享和网络整理,不保证内容的准确性,如有侵权内容,可联系管理员处理 点击这里给我发消息
标签: