缓动类gs.TweenLite示例

网上看到的运用缓动类载入图片的一个类 拿来试验一下
稍作改动 记录一下防止忘记 库中有个图片MiMi
package 

{

	import flash.display.Sprite;

	import flash.display.BitmapData;

	import flash.geom.Rectangle;

	import flash.display.Bitmap;

	import flash.geom.Point;

	import flash.events.MouseEvent;



	import gs.TweenLite;

	import gs.easing.Back;



	public class ImageUp extends Sprite

	{

		var _originalImageData:BitmapData;

		var _cols:uint = 5;

		var _rows:uint = 5;

		var _imgArr:Array = new Array();

		var _w:Number = 0;

		var _h:Number = 0;

		var _flag:Boolean = false;



		public function ImageUp()

		{

			init();

		}





		private function init():void

		{

			//MiMi是库中导入的一张图片

			_originalImageData = new MiMi();

			//计算每个小块的宽度、高度

			_w = _originalImageData.width / _cols;

			_h = _originalImageData.height / _rows;



			var i:uint = 0,j:uint = 0;

			for (i=0; i<_rows; i++)

			{

				for (j=0; j<_cols; j++)

				{

					var _imgCell:BitmapData = new BitmapData(_w,_h);

					//关键:从原图中复制相应的小区域像素到imgCell中

					_imgCell.copyPixels(_originalImageData,

					new Rectangle(j*_w,i*_h,_w,_h),

					new Point());

					var _sprite:Sprite = new Sprite();

					_sprite.addChild(new Bitmap(_imgCell));



					//定位

					_sprite.x = j * _w;

					_sprite.y = i * _h;



					this.addChild(_sprite);

					_imgArr.push(_sprite);

				}

			}

			this.stage.addEventListener(MouseEvent.CLICK,mouseClick);

			begin();

		}





		private function mouseClick(e:MouseEvent)

		{

			if(_flag)

			{

				_flag=false;

				begin();

			}

			

		}



		private function begin():void

		{

			for (var i:uint=0;i<_imgArr.length; i++)

			{

				if(i<_imgArr.length-1)

				{

					TweenLite.from(_imgArr[i],0.5,{delay:0.1*i,y:(_flag?-1:1)*_h*_rows,alpha:0,ease:Back.easeOut});

				}

				else

				{

					TweenLite.from(_imgArr[i],0.5,{delay:0.1*i,y:(_flag?-1:1)*_h*_rows,alpha:0,ease:Back.easeOut,onComplete:toFlag});

				}

			}

			

		}

		

		private function toFlag():void

		{

			trace(_flag);

			_flag = true;

		}

	}

}







你可能感兴趣的:(it)