Ex06_ex02
♥0 |
Line 42 |
Modified 2011-06-30 18:16:26 |
MIT License
archived:2017-03-20 05:38:19
ActionScript3 source code
/**
* Copyright shuto.suzuki ( http://wonderfl.net/user/shuto.suzuki )
* MIT License ( http://www.opensource.org/licenses/mit-license.php )
* Downloaded from: http://wonderfl.net/c/k48T
*/
package
{
import flash.display.Sprite;
import flash.display.StageAlign;
import flash.display.StageScaleMode;
import flash.events.Event;
[SWF(width=466,height=466,backgroundColor=0x000000)]
public class Ex06_ex02 extends Sprite
{
// 配列の宣言
private var arr:Array = [];
// Ballクラスを扱う変数を宣言
private var ball:Ball;
public function Ex06_ex02()
{
// ステージの設定(おまじない)
stage.scaleMode = StageScaleMode.NO_SCALE;
stage.align = StageAlign.TOP_LEFT;
// 100個ボールを作るためのループ
for(var i:uint=0; i<20; i++){
// ballを初期化
ball = new Ball();
// 配列arrのi番目の要素にballを入れる
arr[i] = ball;
// ballの位置の設定
ball.x = 233;
ball.y = 233;
addChild(ball);
}
addEventListener(Event.ENTER_FRAME, onEnterFrame);
}
private function onEnterFrame(e:Event):void{
for(var i:uint=0; i<20; i++){
arr[i].x += arr[i].vx;
arr[i].y += arr[i].vy;
}
}
}
}
import flash.display.Sprite;
class Ball extends Sprite{
public var vx:Number = Math.random() * 10 - 5;
public var vy:Number = Math.random() * 10 - 5;
public function Ball(){
// 円を描く
graphics.beginFill(0xFFFFFF * Math.random());
graphics.drawCircle(0, 0, 10);
graphics.endFill();
}
}