物体拡大効果

1526 ワード

物体の拡大:
package{

	import flash.display.Sprite;
	import flash.events.Event;

	/**
	 * @author zkl
	 */
	public class ScaleObject extends Sprite {

		private var _obj:Object;
		private var _container:Object;

		private var angle:Number = 0;
		private var centerScale:Number;
          
		private var speed:Number;
            
		// : , , , 
		public function ScaleObject(obj:Object,container:Object,centerScale:Number=0.2,speed:Number=0.3) {
                
			_obj=obj;
			_container=container;
			this.centerScale=centerScale;
			this.speed=speed;
             
			init();
             
		}
		private function init():void {
			_obj.addEventListener(Event.ENTER_FRAME, enterFrame);
			_obj.addEventListener(Event.REMOVED_FROM_STAGE, remove);
           
		}
		private function enterFrame(event:Event):void {

			_obj.scaleX = _obj.scaleY = centerScale +Math.sin(angle);
             
			angle += speed;
               
			if (_obj.scaleX>=1) {
				_obj.scaleX = _obj.scaleY=1;
				_obj.removeEventListener(Event.ENTER_FRAME, enterFrame);
                // , 
			}
		}
		private function remove(e:Event):void {

			_obj.removeEventListener(Event.REMOVED_FROM_STAGE, remove);
			_obj=null;
			_container=null;

		}
	}
}