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

Adobe Kularでカラフルに染め上げてみるテスト02

Get Adobe Flash player
by paq 30 Jan 2009
// forked from paq's Adobe Kularでカラフルに染め上げてみるテスト01
// forked from paq's 何かと便利な基本体
package {
	import flash.display.*;
	import flash.events.*;
        import flash.text.*;
	import flash.xml.*;
	import flash.net.*;
	import flash.utils.*;
	
        [ SWF( width = "465" , height = "465" , backgroundColor = "0xFFFFFF" , frameRate = "48" ) ]

	public class Main extends Sprite{
                private var colorXML:XML;
                private var swatchList:Array;
                private var swatchSprite:Sprite = new Sprite();
		private var colorTimer:Timer;
		private var textFields:TextField;
		
		public function Main():void {
			var loader:URLLoader = new URLLoader();
			loader.load(new URLRequest("http://kuler.adobe.com/kuler/services/theme/getList.cfm?listtype=random"));
			loader.addEventListener(Event.COMPLETE,loadComplete);
                        
                        addChild(swatchSprite);

			addEventListener(Event.ENTER_FRAME,update)
		}

                //Adobe KularのXML取得
	        private function loadComplete(e:Event):void {

			//XML・色取得
			colorXML = new XML(e.target.data);

                        var txtFmt:TextFormat = new TextFormat();
                        txtFmt.font="Arial"
                        txtFmt.align = TextFormatAlign.CENTER;
                        txtFmt.color="0x000000"
                        txtFmt.size=30

                        textFields = new TextField();
                        textFields.defaultTextFormat = txtFmt;
                        textFields.multiline=true;
                        textFields.autoSize=TextFieldAutoSize.LEFT;
                        textFields.x = 0;
                        textFields.y = 100;

                        addChild(textFields);

                        //setKular()

			//カラーチェンジタイマースタート!
			colorTimer = new Timer(5000, 0);
			colorTimer.addEventListener(TimerEvent.TIMER, setKular);
			colorTimer.start();                      
		}

	        private function setKular(e:TimerEvent):void {
                        textFields.text=getSwatches();

                        var g:Graphics = swatchSprite.graphics;
                        g.clear();
                        g.beginFill (swatchList[0], 1.0);
                        g.drawRect  ( 0, 0 , 465/5 , 465);
                        g.beginFill (swatchList[1], 1.0);
                        g.drawRect  ( 93, 0 , 465/5 , 465);
                        g.beginFill (swatchList[2], 1.0);
                        g.drawRect  ( 186, 0 , 465/5 , 465);
                        g.beginFill (swatchList[3], 1.0);
                        g.drawRect  ( 279, 0 , 465/5 , 465);
                        g.beginFill (swatchList[4], 1.0);
                        g.drawRect  ( 372, 0 , 465/5 , 465);
                }

		//スウォッチ取得
		private function getSwatches():String {
			swatchList = new Array();
			
			var allSwatchesCount:uint = colorXML..swatches.length();
			var rand:Number =  Math.random()*allSwatchesCount>>0;
			var targetSwatches:XML = colorXML..swatches[rand];
		
		        var r:uint;
			var g:uint;
			var b:uint;

			for each(var swatch:XML in targetSwatches.swatch){
				r = swatch.c1*0xFF >> 0;
				g = swatch.c2*0xFF >> 0;
				b = swatch.c2*0xFF >> 0;
				var color:uint = r << 16 | g << 8 | b;
				swatchList.push(color);
			}

                        return colorXML..theme[rand].label[0];
		}

		private function update(e:Event):void {
                        
		}
	}

}