flash on 2010-2-9
♥0 |
Line 58 |
Modified 2010-02-09 11:55:22 |
MIT License
archived:2017-03-20 05:43:37
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/ifdY
*/
package
{
import flash.display.Sprite;
import flash.events.Event;
[SWF(width="465", height="465", backgroundColor="0x000000", frameRate="30")]
public class EF1 extends Sprite
{
/**
* property
*/
private var _animationFrames:Array;
private var _ball:Sprite;
private var _startX:Number = 0;
private var _endX:Number = stage.stageWidth;
private var _frameCount:int = 0; // 再生ヘッド
private var _frameLimit:int = 30; // 最大コマ数
/**
* constructer
*/
function EF1()
{
// コマごとに変化する数値を生成する
_animationFrames = generateAnimationFrames();
trace(_animationFrames)
// グラフィックを描画
_ball = new Sprite();
_ball.graphics.beginFill( 0xFFCC00 );
_ball.graphics.drawCircle( 0, stage.stageHeight / 2, 5 );
_ball.graphics.endFill();
// 表示OCに追加
addChild( _ball );
//_ball.x = 0;
//_ball.y = stage.stageHeight / 2;
// レンダリング開始
start();
}
/**
* コマごとに変化する数値を生成
*/
private function generateAnimationFrames() :Array
{
var tmp:Array = new Array();
var tmpX:Number = _startX;
var easeRatio:Number = 0.2;
for( var i:int = 0; i < _frameLimit; i ++ )
{
tmpX += ( _endX - tmpX ) * easeRatio;
tmp.push( tmpX );
}
return tmp;
}
/**
* アニメーション部分
*/
private function render( event:Event ) :void
{
if( _frameCount < _frameLimit )
{
_ball.x = _animationFrames[ _frameCount ];
}
else
{
//stop();
_frameCount = 0;
}
_frameCount ++;
}
/**
* 開始メソッド・停止メソッド
*/
public function start() :void
{
addEventListener( Event.ENTER_FRAME, render );
}
public function stop() :void
{
removeEventListener( Event.ENTER_FRAME, render );
}
}
}