One possible use for this example is to simulate a fly, randomly buzzing around a room.
package {
import flash.display.Sprite;
import flash.events.Event;
public class Main extends Sprite {
private var _sprite:Sprite= new Sprite( );
public function Main( ) {
_sprite.graphics.beginFill(0xffffff, 100);
_sprite.graphics.drawCircle(0, 0, 25);
_sprite.graphics.beginFill(0x000000, 100);
_sprite.graphics.drawCircle(20, 0, 5);
_sprite.x = 100;
_sprite.y = 100;
addChild(_sprite);
addEventListener(Event.ENTER_FRAME, onEnterFrame);
}
public function onEnterFrame(event:Event):void {
var dx:Number = mouseX - _sprite.x;
var dy:Number = mouseY - _sprite.y;
var radians:Number = Math.atan2(dy, dx);
_sprite.rotation = radians * 180 / Math.PI;
}
}
}
Related examples in the same category