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: 普通の時計 - Clock

Get Adobe Flash player
by goma000_2005 29 Jul 2009
    Embed
// forked from rsakane's 普通の時計 - Clock
package
{
	import flash.display.Sprite;
	import flash.events.Event;
	import flash.text.TextField;
	import flash.text.TextFormat;
	
	[SWF(width="465", height="465", frameRate="30", backgroundColor="0xffffff")]
	public class Main extends Sprite
	{
		private var seconds:Vector.<Sprite> = new Vector.<Sprite>();
		private var minutes:Vector.<Sprite> = new Vector.<Sprite>();
		private var hours:Vector.<Sprite> = new Vector.<Sprite>();
		private var stf:TextField;
		private var mtf:TextField;
		private var htf:TextField;
		
		public function Main()
		{
			for (var degree:int = -190; degree < 270; degree += 6)
			{
				var second:Sprite = new Clock(0x0);
				second.rotation = degree;
				second.x = 230 + Math.cos(degree * Math.PI / 180) * 210;
				second.y = 230 + Math.sin(degree * Math.PI / 180) * 210;
				addChild(second);
				seconds.push(second);
				
				var minute:Sprite = new Clock(0x393939);
				minute.rotation = degree;
				minute.x = 230 + Math.cos(degree * Math.PI / 180) * 150;
				minute.y = 230 + Math.sin(degree * Math.PI / 180) * 150;
				minute.scaleX = minute.scaleY = 0.9;
				addChild(minute);
				minutes.push(minute);
			}
			
			for (degree = -90; degree < 270; degree += 15)
			{
				var hour:Sprite = new Clock(0x666666);
				hour.rotation = degree;
				hour.x = 230 + Math.cos(degree * Math.PI / 180) * 90;
				hour.y = 230 + Math.sin(degree * Math.PI / 180) * 90;
				addChild(hour);
				hours.push(hour);
			}
			
			var date:Date = new Date();
			for (var i:int = 0; i <= date.seconds; i++)
			{
				seconds[i].alpha = 1.0;
			}
			
			for (i = 0; i <= date.minutes; i++)
			{
				minutes[i].alpha = 1.0;
			}
			
			for (i = 0; i <= date.hours; i++)
			{
				hours[i].alpha = 1.0;
			}
			
			htf = createTextField((String(date.hours).length == 1) ? "0" + String(date.hours) : String(date.hours), 41, 170, 160);
			addChild(htf);
			
			mtf = createTextField((String(date.minutes).length == 1) ? "0" + String(date.minutes) : String(date.minutes), 41, 210, 200);
			addChild(mtf);
			
			stf = createTextField((String(date.seconds).length == 1) ? "0" + String(date.seconds) : String(date.seconds), 41, 250, 240);
			addChild(stf);
			
			addEventListener(Event.ENTER_FRAME, onEnterFrame);
		}
		
		private function onEnterFrame(event:Event):void
		{
			var date:Date = new Date();
			seconds[date.seconds].alpha = 1.0;
			minutes[date.minutes].alpha = 1.0;
			hours[date.hours].alpha = 1.0;
			
			stf.text = (String(date.seconds).length == 1) ? "0" + String(date.seconds) : String(date.seconds);

			var i:int;
			if (date.seconds == 0)
			{
				for (i = 1; i < 60; i++) seconds[i].alpha = 0.0;				
				mtf.text = (String(date.minutes).length == 1) ? "0" + String(date.minutes) : String(date.minutes);
			}
			
			if (date.minutes == 0)
			{
				for (i = 1; i < 60; i++) minutes[i].alpha = 0.0;
				htf.text = (String(date.hours).length == 1) ? "0" + String(date.hours) : String(date.hours);
			}
			
			if (date.hours == 0)
			{
				for (i = 1; i < 24; i++) hours[i].alpha = 0.0;
			}
		}
		
		private function createTextField(text:String, size:int, x:int, y:int):TextField
		{
			var tf:TextField = new TextField();
			tf.x = x, tf.y = y;
			tf.defaultTextFormat = new TextFormat("typwWriter_", size, 0x0, true);
			tf.text = text;
			tf.autoSize = "left";
			addChild(tf);
			
			return tf;
		}
	}
}

import flash.display.Sprite;

class Clock extends Sprite
{
	public function Clock(color:int)
	{
		graphics.beginFill(color);
		graphics.drawRect(0, 0, 15, 15);
		graphics.endFill();
		
		alpha = 0.0;
	}
}