flash on 2010-2-18

by tan_go238
円運動
♥0 | Line 50 | Modified 2010-02-18 17:05:29 | MIT License
play

ActionScript3 source code

/**
 * Copyright tan_go238 ( http://wonderfl.net/user/tan_go238 )
 * MIT License ( http://www.opensource.org/licenses/mit-license.php )
 * Downloaded from: http://wonderfl.net/c/3byB
 */

/*
 * 円運動
 */
package {
    import flash.display.Sprite;
    import flash.events.Event;
    import flash.events.TimerEvent;
    import flash.utils.Timer;
    
    public class FlashTest extends Sprite {
    		
   		/***********  CONSTANTS ***********/
    		private const stageWidth:int  = stage.stageWidth;
    		private const stageHeight:int = stage.stageHeight;
    		private const centerX:int = stageWidth / 2;
    		private const centerY:int = stageHeight / 2;
    		private const radius:Number  = 30;
    		
   		/***********  VARIABLES ***********/
   		private var particles:Array = new Array;
   		private var degree:int = 0;
   		private var posX:int = stageWidth - radius;
   		private var posY:int = stageHeight - radius;
   		private var particle:Particle = new Particle();
   		private var timer:Timer;
   		
        public function FlashTest() {
            addEventListener( Event.ADDED_TO_STAGE, init );
        }

        	/***********  FUNCTIONS ***********/
        private function init(e:Event):void 
        {
        		removeEventListener( Event.ADDED_TO_STAGE, init );
			particle.x = stageWidth / 2;
			particle.y = stageHeight / 2;
			addChild(particle);
			
            //addEventListener(Event.ENTER_FRAME, loop);
            timer = new Timer(30, 0);
            timer.addEventListener(TimerEvent.TIMER,loop);
            timer.start();
        }
        
        private function loop(e:TimerEvent):void 
        {
        		var radian:Number = Math.PI/180*degree;
        		posX = particle.x;
        		particle.x = centerX + radius * Math.cos(radian);
        		particle.y = centerY + radius * Math.sin(radian);
			degree += 5;
        }
    }
}

import flash.display.Sprite;

class Particle extends Sprite
{
    public function Particle()
    {
        graphics.beginFill(0x000);
        graphics.drawCircle(0, 0, 12);
        graphics.endFill();
    }
}

Forked