flash on 2010-6-10
♥0 |
Line 64 |
Modified 2010-06-10 16:17:24 |
MIT License
archived:2017-03-20 14:15:47
ActionScript3 source code
/**
* Copyright aaharu ( http://wonderfl.net/user/aaharu )
* MIT License ( http://www.opensource.org/licenses/mit-license.php )
* Downloaded from: http://wonderfl.net/c/efW0
*/
package {
import flash.display.Sprite;
import flash.display.StageAlign;
import flash.display.StageScaleMode;
import flash.events.Event;
import flash.events.MouseEvent;
public class ipl_flash_2010_04_p2 extends Sprite {
private var array:Array = [];
public function ipl_flash_2010_04_p2() {
stage.scaleMode = StageScaleMode.NO_SCALE;
stage.align = StageAlign.TOP_LEFT;
for(var i:uint = 0; i < 100; i++) {
var sp:Ball = new Ball(0, Math.random() * 10 + 1, 10, Math.random() * 0xFFFFFF);
sp.x = Math.random() * stage.stageWidth;
sp.y = -Math.random() * 100 - 10;
array.push(sp);
addChild(sp);
}
addEventListener(Event.ENTER_FRAME, onEnterFrame);
// マウスダウンイベント追加
stage.addEventListener(MouseEvent.MOUSE_DOWN, onMouseDown);
}
private function onMouseDown(e:MouseEvent):void {
// エンターフレームイベントを削除(アニメーションが止まる)
removeEventListener(Event.ENTER_FRAME, onEnterFrame);
// マウスダウンされたら、マウスアップイベント追加
stage.addEventListener(MouseEvent.MOUSE_UP, onMouseUp);
}
private function onMouseUp(e:MouseEvent):void {
// エンターフレームイベントを再び追加
addEventListener(Event.ENTER_FRAME, onEnterFrame);
// マウスアップ時に、マウスアップイベントを削除
stage.removeEventListener(MouseEvent.MOUSE_UP, onMouseUp);
}
private function onEnterFrame(e:Event):void {
for(var i:uint = 0; i < 100; i++) {
array[i].y += array[i].vy;
if(array[i].y > stage.stageHeight + 10) {
array[i].y = -10;
array[i].vy = Math.random() * 10 + 1;
}
}
}
}
}
import flash.display.Sprite;
class Ball extends Sprite {
private var _vx:Number;
private var _vy:Number;
public function get vx():Number {
return _vx;
}
public function set vx(v:Number):void {
_vx = v;
}
public function get vy():Number {
return _vy;
}
public function set vy(v:Number):void {
_vy = v;
}
public function Ball(vx:Number, vy:Number, r:Number, color:uint) {
_vx = vx;
_vy = vy;
graphics.beginFill(color);
graphics.drawCircle(0, 0, r);
graphics.endFill();
}
}