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でカラフルに染め上げてみるテスト03(そうめんにしてみた)

// forked from paq's Adobe Kularでカラフルに染め上げてみるテスト02
// forked from paq's Adobe Kularでカラフルに染め上げてみるテスト01
// forked from paq's 何かと便利な基本体
package {
	import flash.display.*;
        import org.libspark.thread.Thread;
        import org.libspark.thread.EnterFrameThreadExecutor;
	
        [ SWF( width = "465" , height = "465" , backgroundColor = "0xFFFFFF" , frameRate = "48" ) ]

	public class Main extends Sprite{

		public function Main():void {
                        Thread.initialize(new EnterFrameThreadExecutor());
			
			var main:MainThread = new MainThread(this);
			main.start();
		}
	}
}


//-------------------------------------------------------------
//MainThread
//そうめん処理クラス
//-------------------------------------------------------------

import flash.display.*;
import flash.text.*;
import flash.net.*;

import org.libspark.thread.Thread;
import org.libspark.thread.threads.tweener.TweenerThread;
import org.libspark.thread.utils.*;
import org.libspark.thread.threads.net.URLLoaderThread;

internal class MainThread extends Thread {
	public function MainThread(layer:DisplayObjectContainer) {
		_layer = layer;
	}
	
	private var _layer:DisplayObjectContainer;
	private var _shape:DisplayObject;
	private var _loaders:URLLoaderThread;
        private var colorXML:XML;
        private var swatchList:Array;
        private var swatchSprite:Sprite = new Sprite();
	private var textFields:TextField;
	
	//初期処理
	override protected function run():void {
		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;

                _layer.addChild(swatchSprite);
                _layer.addChild(textFields);

		_loaders = new URLLoaderThread( new URLRequest("http://kuler.adobe.com/kuler/services/theme/getList.cfm?listtype=random") );
		_loaders.start();
		_loaders.join();

		next(loadComplete)
	}

	//終了処理 特に行われるないと思う。
	protected override function finalize():void {
			_loaders = null;
	}

	//ロード完了
	private function loadComplete():void {
		//XML・色取得
		colorXML = new XML(_loaders.loader.data);

                next(setSwatches);
	}

	//スウォッチ描画
	private function setSwatches():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);

                sleep(5000);
                next(setSwatches);
	}

	//スウォッチ取得
	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];
	}

}