Ex06_ex01
♥0 |
Line 40 |
Modified 2011-06-30 18:09:40 |
MIT License
archived:2017-03-20 05:38:21
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/dzlX
*/
package
{
import flash.display.Sprite;
import flash.display.StageAlign;
import flash.display.StageScaleMode;
import flash.events.Event;
[SWF(width=465,height=465,backgroundColor=0x000000)]
public class Ex06_ex01 extends Sprite
{
// 配列の宣言
private var arr:Array = [];
// Ballクラスを扱う変数を宣言
private var ball:Ball;
public function Ex06_ex01()
{
// ステージの設定(おまじない)
stage.scaleMode = StageScaleMode.NO_SCALE;
stage.align = StageAlign.TOP_LEFT;
// 100個ボールを作るためのループ
for(var i:uint=0; i<10; i++){
// ballを初期化
ball = new Ball();
// 配列arrのi番目の要素にballを入れる
arr[i] = ball;
// ballの位置の設定
ball.x = 10;
ball.y = 10 + i*20;
addChild(ball);
}
addEventListener(Event.ENTER_FRAME, onEnterFrame);
}
private function onEnterFrame(e:Event):void{
for(var i:uint=0; i<10; i++){
arr[i].x += arr[i].vx;
}
}
}
}
import flash.display.Sprite;
class Ball extends Sprite{
public var vx:Number = 5;
public function Ball(){
// 円を描く
graphics.beginFill(0xFFFFFF * Math.random());
graphics.drawCircle(0, 0, 10);
graphics.endFill();
}
}