In case Flash no longer exists; a copy of this site is included in the Flashpoint archive's "ultimate" collection.

Dead Code Preservation :: Archived AS3 works from wonderfl.net

読み込みの時くるくる回るやつ

読み込みの時くるくる回るやつ
Get Adobe Flash player
by geko 09 Apr 2010
/**
 * Copyright geko ( http://wonderfl.net/user/geko )
 * MIT License ( http://www.opensource.org/licenses/mit-license.php )
 * Downloaded from: http://wonderfl.net/c/8m6p
 */

//読み込みの時くるくる回るやつ

package {
	import flash.display.Sprite;
	import flash.events.MouseEvent;
	
	public class FlashTest extends Sprite {
		private var loadingA:Loading;
		private var loadingB:Loading;
		
    		public function FlashTest() {
    			//矩形でくるくる
    			loadingA = new Loading(12,"rectangle");
			addChild(loadingA);
			loadingA.x = stage.stageWidth/2-25;
			loadingA.y = stage.stageHeight/4;

			//円形でくるくる
			loadingB = new Loading(8,"circle");
			addChild(loadingB);
			loadingB.x = stage.stageWidth/2+25;
			loadingB.y = stage.stageHeight/4;
			
			//おまけ:クリックしたら...
			stage.addEventListener(MouseEvent.CLICK, changeEnabled);
        }
        private function changeEnabled(event:MouseEvent):void{
			if(loadingA.enabled){
				loadingA.enabled = false;
				loadingB.enabled = false;
				return;
			}
			loadingA.enabled = true;
			loadingB.enabled = true;
		}
    }
}

import flash.display.Sprite;
import flash.utils.Timer;
import flash.events.TimerEvent;

/*** くるくるクラス ***/
class Loading extends Sprite{
	
	// num:uint		円を構成する個数
	// type:String	形("rectangle", "circle", "rainbow"(未実装))
	public function Loading(num:uint = 12, type:String = "rectangle"){
		//描画
		for(var i:int = 0;i < num;i++){
			var shape:LoadingGraphics = new LoadingGraphics(type,i,num);
			shape.rotation = -360/num*i;
			addChild(shape);
			shapes.push(shape);
		}
			
		//Timerの設定
		timer = new Timer(60);
		timer.addEventListener(TimerEvent.TIMER,update);
		timer.start();
	}
				
	//描画の更新
	private function update(event:TimerEvent):void{
		for each(var shape:LoadingGraphics in shapes) shape.update();
	}
		
	/*** プロパティ ***/
	private var timer:Timer;
	private var shapes:Array = [];
			
	public function set enabled(val:Boolean):void{
		for each(var shape:LoadingGraphics in shapes) shape.enabled = val;
		//falseの時はtimer止めた方が良いのか?
	}
	public function get enabled():Boolean{
		return shapes[0].enabled;
	}
}


/*** くるくるの描画クラス ***/
class LoadingGraphics extends Sprite{
	public function LoadingGraphics(type:String,i:int,num:uint){
		this.type = type;
		this.i = i;
		this.num = num;
		
		update();
	}
		
	//更新
	internal function update():void{
		this.graphics.clear();
		this.graphics.beginFill(enabled ? 0x333333+0x111111*i : 0xaaaaaa);
		drawShape();
		this.graphics.endFill();
		if(++i >= num) i = 0;
	}
		
	//typeに応じて形を変更
	private function drawShape():void{
		switch(type){
			case "rectangle":	this.graphics.drawRoundRect(-1.5,8,3,8,1,1); break;
			case "circle":		this.graphics.drawCircle(0,12,3);
			//macの虹のやつも作りたいな.
			//case "rainbow":
		}
	}
		
	public var enabled:Boolean = true;
	private var type:String = "rectangle"
	private var i:int = 0;
	private var num:uint = 12;
}