Oscillation Animation : Oscillation « Animation « Flash / Flex / ActionScript






Oscillation Animation

 
package {
    import flash.display.Sprite;
    import flash.events.Event;
    
    public class Main extends Sprite {
        private var _sprite:Sprite;
        private var _angle:Number = 45;
        private var _radius:Number = 200;
        
        public function Main(  ) {
            _sprite = new Sprite(  );
            _sprite.graphics.beginFill(0x0000ff, 100);
            _sprite.graphics.drawCircle(0, 0, 5);
            _sprite.graphics.endFill(  );
            _sprite.x = 0;
            _sprite.y = 100;
            addChild(_sprite);
            addEventListener(Event.ENTER_FRAME, onEnterFrame);
        }
        
        public function onEnterFrame(event:Event):void {
            _sprite.x = 200 + Math.sin(_angle) * _radius;
            _sprite.y = 200 + Math.cos(_angle) * _radius;
            _angle += .05;
        }
    }    
}

        








Related examples in the same category

1.One possible use for this example is to simulate a fly, randomly buzzing around a room.