Chapter 39 Example 1
♥0 |
Line 30 |
Modified 2010-02-10 02:44:14 |
MIT License
archived:2017-03-09 19:56:50
ActionScript3 source code
/**
* Copyright actionscriptbible ( http://wonderfl.net/user/actionscriptbible )
* MIT License ( http://www.opensource.org/licenses/mit-license.php )
* Downloaded from: http://wonderfl.net/c/oa8S
*/
package {
import flash.display.*;
import flash.events.TimerEvent;
import flash.utils.Timer;
[SWF(frameRate="1")]
public class ch39ex1 extends Sprite {
protected var ball:DisplayObject;
public function ch39ex1() {
ball = new Ball();
ball.y = stage.stageHeight/2;
addChild(ball);
// fps = frames/second
var fps:int = 60;
// 1/fps = seconds/frame, 1/fps*1000 = milliseconds/frame
var mspf:int = Math.round(1 / fps * 1000);
var t:Timer = new Timer(mspf);
t.addEventListener(TimerEvent.TIMER, onTimer);
t.start();
}
protected function onTimer(event:TimerEvent):void {
ball.x += 0.5;
event.updateAfterEvent();
}
}
}
import flash.display.Shape;
class Ball extends Shape {
public function Ball(color:uint = 0xff0000, size:Number = 50) {
graphics.beginFill(color);
graphics.drawCircle(0, 0, size);
}
}