Wonderfl Book vol.01

by genny
♥0 | Line 68 | Modified 2010-02-16 18:19:08 | MIT License
play

ActionScript3 source code

/**
 * Copyright genny ( http://wonderfl.net/user/genny )
 * MIT License ( http://www.opensource.org/licenses/mit-license.php )
 * Downloaded from: http://wonderfl.net/c/nYY4
 */

package
{
	
	import flash.display.Sprite;
	import flash.events.Event;
	import flash.filters.GlowFilter;
	[SWF(backgroundColor="0x000000", width="800", height="600", frameRate="45")]
	public class LikeTimeLine1 extends Sprite
	{
		//	Property
		private var _ball:Sprite;
		private var _startX:int = 0;
		private var _startY:int = stage.stageHeight/2;
		private var _endX:int = stage.stageWidth;
		private var _frameCount:int = 0;
		private var _frameCountLimit:int = 30;
		private var _animationFrames:Array;
		
		
		//	Constructer
		function LikeTimeLine1()
		{
			init();
		}
		
		
		//	initialize
		private function init() :void
		{
			
			//	フレーム数分の座標値を算出
			_animationFrames = generateAnimationFrames();
			
			//	ボールを生成
			_ball = new Sprite();
			_ball.graphics.beginFill( 0x66CC33 );
			_ball.graphics.drawCircle( 0, 0, 5 );
			_ball.graphics.endFill();
			addChild( _ball );
			
			_ball.x = _startX;
			_ball.y = _startY;
			_ball.filters = [ new GlowFilter( 0x66CC33, 1, 20, 20, 2, 1) ];
			
			start();
		}
		
		
		/**
		*	Handler
		*/
		private function render( event:Event ) :void
		{
			
			if( _frameCount < _frameCountLimit )
			{
				_ball.x = _animationFrames[ _frameCount ];
			}
			else
			{
				stop();
			}
			
			trace(_frameCount)
			_frameCount ++;
		}
		
		
		/**
		*	Listener
		*/
		private function start() :void
		{
			addEventListener( Event.ENTER_FRAME, render );
		}
		
		private function stop() :void
		{
			removeEventListener( Event.ENTER_FRAME, render );
		}
		
		
		/**
		*	移動座標の算出を行う
		*/
		private function generateAnimationFrames() :Array
		{
			var arr:Array = new Array();
			var tmpX:Number = _startX;
			var len:int = _frameCountLimit;
			var easeRatio:Number = 0.2;
			
			for( var i:int = 0; i < len; i ++ )
			{
				tmpX += ( _endX - tmpX ) * easeRatio;
				arr.push( tmpX )
			}
			
			return arr;
			
		}
		
		
	}
}

Forked