向心力
This code is illustrated in the following entry.
http://level0.kayac.com/2009/07/flashlite11sincos.php
@author 9re
package
{
import flash.display.MovieClip;
import flash.display.Shape;
import flash.events.Event;
import flash.events.TimerEvent;
import flash.utils.Timer;
/**
* This code is illustrated in the following entry.
http://level0.kayac.com/2009/07/flashlite11sincos.php
* @author 9re
*/
public class CircularMotion extends MovieClip
{
private const K:Number = 0.1;
private const R:Number = 120;
private var _shp:Shape;
public function CircularMotion()
{
_shp = new Shape();
_shp.graphics.beginFill(0);
_shp.graphics.drawCircle(0, 0, 15);
_shp.graphics.endFill();
_shp.x = stage.stageWidth / 2 + R;
_shp.y = stage.stageHeight / 2;
graphics.lineStyle(1, 0xff0000);
graphics.moveTo(_shp.x, _shp.y);
addChild(_shp);
addEventListener(Event.ENTER_FRAME, enterFrameHandler);
var timer:Timer = new Timer(20000);
timer.addEventListener(TimerEvent.TIMER, function (e:TimerEvent):void
{
graphics.clear();
graphics.lineStyle(1, 0xff0000);
graphics.moveTo(_shp.x, _shp.y);
});
timer.start();
}
private function enterFrameHandler(e:Event):void
{
_shp.x -= (_shp.y - stage.stageHeight / 2) * K;
_shp.y += (_shp.x - stage.stageWidth / 2) * K;
graphics.lineTo(_shp.x, _shp.y);
}
}
}