flash on 2009-12-27

by yama3
♥0 | Line 37 | Modified 2009-12-27 22:56:07 | MIT License
play

ActionScript3 source code

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

package {
	import flash.display.*;
	import flash.events.Event;
	
	[SWF(frameRate="30", width="465", height="465")]

	public class MyFirstAnimation extends Sprite {
		private var _circle:Circle;

		public function MyFirstAnimation() {
			//クラスCircleのインスタンスを作る
			_circle = new Circle(10);
			//半透明
			_circle.alpha = 0.25;
			_circle.vx = 3;
			_circle.vy = 4;

			//最初の位置を中央にセット
			_circle.x = 465/2;
			_circle.y = 465/2;

			//表示リストに追加
			addChild(_circle);

			//1フレームごとに実行する処理に追加
			addEventListener(Event.ENTER_FRAME, enterFrameHandler);
		}

		//フレームごとに行われる処理
		private function enterFrameHandler(e:Event):void {
			//1フレーム分動かす
			_circle.move();
		}
	}
}

import flash.display.Sprite;

class Circle extends Sprite {
	public var vx:Number;
	public var vy:Number;
	public var radius:Number;

	//コンストラクタ
	public function Circle(_radius:Number, _fillColor:uint = 0x000000) {
		graphics.beginFill(_fillColor);
		graphics.drawCircle(0,0,_radius);
		graphics.endFill();
		radius = _radius;
	}

	public function move():void {
		x += vx;
		y += vy;
	}
}