package { import mx.controls.Image; import flash.utils.Timer; import flash.events.TimerEvent; public class graphic_flex_animation_bubbles_BallTest { function graphic_flex_animation_bubbles_BallTest(root_ball : Image, N : Number) { this._root_ball = root_ball; this._N = N; // number of objects this._ballsO = new Array(); this._isRunning = false; } protected var _N : Number; protected var _ballsO : Array; protected var _isRunning : Boolean; protected var _root_ball : Image; protected var _F : Number = 0; protected var _lastF : Number = 0; protected var _lastTime : Date; private var _frameTimer : Timer; private var _fpsTimer : Timer; public var _showFPS : Function = null; public function startN(N : Number) : void { this._N = N; this.start(); } public function start() : void { if (this._isRunning) return; this._isRunning = true; this._F = 0; // frames counter for FPS this._lastF = 0; this._lastTime = new Date(); var _this : graphic_flex_animation_bubbles_BallTest = this; var moveBalls : Function = function() : void { if (_this._N > _this._ballsO.length) return; _this._F++; // move balls for (var i : Number = 0; i<_this._N; i++) { _this._ballsO[i].move(); } // process collisions for (i=0; i<_this._N; i++) { for (var j : Number = i+1; j<_this._N; j++) { _this._ballsO[i].doCollide(_this._ballsO[j]); } } } var showFps : Function = function() : void { if (_this._F - _this._lastF < 10) return; var currTime : Date = new Date(); var delta_t : Number = (currTime.getMinutes() - _this._lastTime.getMinutes())*60 + currTime.getSeconds() - _this._lastTime.getSeconds() + (currTime.getMilliseconds() - _this._lastTime.getMilliseconds())/1000.0; var fps : Number = (_this._F - _this._lastF)/delta_t; _this._lastF = _this._F; _this._lastTime = currTime; if (_this._showFPS != null) _this._showFPS.call(_this, Math.round(fps)); } // create all our balls this._ballsO[0] = new Ball(this._root_ball); for (var i : Number =1; i