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

forked from: 時計の勉強

汚いコードですいません。
時計っぽいものの練習
すんげー分かりづらい
勉強なので悪しからず
Get Adobe Flash player
by yukick 23 Apr 2010
    Embed
/**
 * Copyright yukick ( http://wonderfl.net/user/yukick )
 * GNU General Public License, v3 ( http://www.gnu.org/licenses/quick-guide-gplv3.html )
 * Downloaded from: http://wonderfl.net/c/lYzp
 */

// forked from gaina's 時計の勉強
//汚いコードですいません。
//時計っぽいものの練習
//すんげー分かりづらい
//勉強なので悪しからず

package  
{
	import adobe.utils.ProductManager;
	import flash.display.Sprite;
	import flash.display.StageAlign;
	import flash.display.StageScaleMode;
	import flash.events.Event;
	import flash.events.TimerEvent;
	import flash.geom.ColorTransform;
	import flash.text.TextField;
	import flash.text.TextFieldAutoSize;
	import flash.utils.Timer;
	/**
	 * ...
	 * @author gaina
	 */
	[SWF(width="600",height="600")]
	public class myClock extends Sprite
	{
		private var date:Date;
		private var second:Number ;
		private var minute:Number;
		private var hour:Number;
		private var Ssp:DRrect;
		private var Msp:DRrect;
		private var Hsp:DRrect;
		private var timer:Timer ;
		private var secTxt:TextField;
		private var minTxt:TextField;
		private var houTxt:TextField;
		private var arr:Array = [];
		private var Sparr:Array = [];
		private var Mparr:Array = [];
		private var Hparr:Array = [];
		private var secArray:Array = [];
		private var minArray:Array = [];
		private var houArray:Array = [];
		
		public function myClock() 
		{
			arr = colorArr();
			
			stage.align = StageAlign.TOP_LEFT;
			stage.scaleMode = StageScaleMode.NO_SCALE;
		
			init();
			
			timer = new Timer(33);
			timer.addEventListener(TimerEvent.TIMER, loop);
			timer.start();
			
		}
		
		public function init():void {
			
			for (var hi:int = 0; hi < 4; hi++) {
				for (var hj:int = 0; hj < 6; hj++) {
					Hsp = new DRrect(0, 0, stage.stageWidth / 6, stage.stageHeight/12);
					Hsp.x = hj * stage.stageWidth / 6;
					Hsp.y = hi * stage.stageHeight / 12;
					var hCt:ColorTransform = new ColorTransform();
					hCt.color = arr[hi][hj];
					Hsp.transform.colorTransform = hCt;
					Hsp.alpha = 0;
					Hparr.push(Hsp);
					addChild(Hsp);
					
					houTxt = new TextField();
					houTxt.autoSize = TextFieldAutoSize.CENTER;
					var htxt:int = 6 * hi + hj;
					var ht:String = String(htxt);
					houTxt.text = ht;
					houTxt.x = Hsp.x;
					houTxt.y = Hsp.y;
					addChild(houTxt);
					houArray.push(houTxt);
				}
			}
			
			for (var mi:int = 0; mi < 6; mi++) {
				for (var mj:int = 0; mj < 10; mj++) {
					Msp = new DRrect(0, 0, stage.stageWidth / 10, stage.stageHeight/18);
					Msp.x = mj * stage.stageWidth / 10;
					Msp.y = stage.stageHeight * 1 / 3 + mi * stage.stageHeight / 18;
					var mCt:ColorTransform = new ColorTransform();
					mCt.color = arr[mi][mj];
					Msp.transform.colorTransform = mCt;
					Msp.alpha = 0;
					Mparr.push(Msp);
					addChild(Msp);
					
					minTxt = new TextField();
					minTxt.autoSize = TextFieldAutoSize.CENTER;
					var mtxt:int = 10 * mi + mj;
					var mt:String = String(mtxt);
					minTxt.text = mt;
					minTxt.x = Msp.x;
					minTxt.y = Msp.y;
					addChild(minTxt);
					minArray.push(minTxt);
				}				
			}
			
			for (var i:int = 0; i < 6; i++) {
				for (var j:int = 0; j < 10; j++) {
					Ssp = new DRrect(0, 0, stage.stageWidth / 10, stage.stageHeight/18);
					Ssp.x = j * stage.stageWidth / 10;
					Ssp.y = stage.stageHeight * 2 / 3 + i * stage.stageHeight / 18;
					var sCt:ColorTransform = new ColorTransform();
					sCt.color = arr[i][j];
					Ssp.transform.colorTransform = sCt;
					Ssp.alpha = 0;
					Sparr.push(Ssp);
					addChild(Ssp);
					
					secTxt = new TextField();
					secTxt.autoSize = TextFieldAutoSize.CENTER;
					var stxt:int = 10 * i + j;
					var st:String = String(stxt);
					secTxt.text = st;
					secTxt.x = Ssp.x+Ssp.width-secTxt.width;
					secTxt.y = Ssp.y;
					addChild(secTxt);
					secArray.push(secTxt);
				}				
			}
			stage.addEventListener(Event.RESIZE, resizeEvent);
		}
		
		public function resizeEvent(event:Event):void {
			for (var i:int = 0; i < 60; i++) {
				removeChild(Sparr[i]);
				removeChild(Mparr[i]);
				removeChild(secArray[i]);
				removeChild(minArray[i]);
				if (i < 24) {
					removeChild(Hparr[i]);
					removeChild(houArray[i]);
				}
			}
			Sparr = [];
			Mparr = [];
			Hparr = [];
			secArray = [];
			minArray = [];
			houArray = [];
			init();
		}
		
		public function loop(event:TimerEvent):void {
			date = new Date();
			second = date.getSeconds();
			minute = date.getMinutes();
			hour = date.getHours();
			Sparr[second].move();
			Mparr[minute].move();
			Hparr[hour].move();
		}

		public function colorArr():Array {
			var ar:Array = [];
			ar.push([0x33CCFF, 0x33CCCC, 0x33CC99, 0x33CC66, 0x33CC33, 0x33CC00, 0x00CCFF, 0x00CCCC, 0x00CC99, 0x00CC66]);
			ar.push([0x00CC33, 0x00CC00, 0x3399FF, 0x3399CC, 0x339999, 0x339966, 0x339933, 0x339900, 0x0099FF, 0x0099CC]);
			ar.push([0x009999, 0x009966, 0x009933, 0x009900, 0x3366FF, 0x3366CC, 0x336699, 0x336666, 0x336633, 0x336600]);
			ar.push([0x0066FF, 0x0066CC, 0x006699, 0x006666, 0x006633, 0x006600, 0x3333FF, 0x3333CC, 0x333399, 0x333366]);
			ar.push([0x333333, 0x333300, 0x3300FF, 0x3300CC, 0x330099, 0x330066, 0x330033, 0x330000, 0x0033FF, 0x0033CC]);
			ar.push([0x003399, 0x003366, 0x003333, 0x003300, 0x0000FF, 0x0000CC, 0x000099, 0x000066, 0x000033, 0x000000]);
			return ar;
		}
	}
}

import flash.display.Sprite;
import flash.events.Event;
class DRrect extends Sprite {
public function DRrect(xx:Number = 0, yy:Number = 0, w:Number = 100, h:Number = 100) {
			graphics.beginFill(0);
			graphics.drawRect(xx, yy, w, h);
			graphics.endFill();
		}
		public function move():void {
			this.alpha = 1;
			this.addEventListener(Event.ENTER_FRAME, onEnter);
		}
		
		private function onEnter(event:Event):void {
			this.alpha -= 0.05;
			if (this.alpha == 0) {
				removeEventListener(Event.ENTER_FRAME, onEnter);
			}
		}
}