flash on 2009-10-31
♥0 |
Line 35 |
Modified 2009-11-01 00:14:36 |
MIT License
archived:2017-03-20 09:39:52
ActionScript3 source code
/**
* Copyright hanaokake ( http://wonderfl.net/user/hanaokake )
* MIT License ( http://www.opensource.org/licenses/mit-license.php )
* Downloaded from: http://wonderfl.net/c/vTHu
*/
package {
import flash.display.Sprite;
public class FlashTest extends Sprite {
public function FlashTest() {
// write as3 code here..
var count:uint = 100; //ボールの数
var gravity:Number = 0.5; //重力加速度
//ボールの作成、初期設定
for (var i = 0; i < count; i++) {
var ball:MovieClip = new MovieClip();
ball.graphics.beginFill(0xffffff * Math.random()); //ボールの塗り設定(色ランダム)
ball.graphics.drawCircle(0, 0, 3); //ボールの座標、半径
ball.graphics.endFill(); //塗りの適用
//ボールの初期位置
ball.x = stage.stageWidth / 2;
ball.y = stage.stageHeight;
//ボールの初期速度
ball.speedX = Math.random() * 10 - 5;
ball.speedY = Math.random() * -8 - 5;
addChild(ball); //ボール設置
//ボールの動きを実行
ball.addEventListener(Event.ENTER_FRAME, moveBall);
}
//ボールの動き設定
function moveBall(evt:Event):void {
var ball:MovieClip = MovieClip(evt.target); //ボールをローカル変数に変換
ball.speedY += gravity; //重力の適用
//ボールに新たな速度適用
ball.x += ball.speedX;
ball.y += ball.speedY;
//ボールが下に落ちた後の設定
if (ball.y > stage.stageHeight) {
//マウス位置によってY方向速度を変える
var mouseHeight:Number = stage.stageHeight - mouseY;
var newSpeedY = Math.random() * (-mouseHeight * 0.03) - 10;
//ボールの位置設定
ball.x = stage.stageWidth / 2;
ball.y = stage.stageHeight;
//ボールの新たな速度設定
ball.speedX = Math.random() * 10 - 5;
ball.speedY = newSpeedY;
}
}
}
}
}