flash on 2009-5-9 ... @author iweek hacker_j5gd_.. forked:0favorite:0lines:92license : All rights reserved modified : 2009-05-09 00:14:14 Embed Tweet package { import flash.display.*; import flash.events.*; import flash.text.*; import flash.utils.*; import caurina.transitions.properties.*; import caurina.transitions.*; /** * ... * @author iweek */ public class DigitalClockTween extends Sprite { private var upperHour:TextField = new TextField(); private var lowerHour:TextField = new TextField(); private var upperMin:TextField = new TextField(); private var lowerMin:TextField = new TextField(); private var upperSec:TextField = new TextField(); private var lowerSec:TextField = new TextField(); private var preSec:int; public function DigitalClockTween(font:String = "arial bold",size:Number = 42, color:Number = 0xCCCCCC ):void { addEventListener(Event.ENTER_FRAME, clockShowTimer); iniTextField(upperHour, font, size, color); iniTextField(lowerHour, font, size, color); iniTextField(upperMin, font, size, color); iniTextField(lowerMin, font, size, color); iniTextField(upperSec, font, size, color); iniTextField(lowerSec, font, size, color); } private function clockShowTimer(event:Event):void { var now:Date = new Date(); var hour:int = now.getHours(); var min:int = now.getMinutes(); var sec:int = now.getSeconds(); if (preSec != sec) { lowerSec.alpha = 0; lowerSec.y = lowerSec.y - 10; upperHour.text = String(int(hour / 10)); lowerHour.text = String(int(hour % 10)); upperMin.text = ":" + String(int(min / 10)); lowerMin.text = String(int(min % 10)); upperSec.text = ":" + String(int(sec / 10)); lowerSec.text = String(int(sec % 10)); Tweener.addTween(lowerSec, { time:0.5, y:yPosition, alpha:1.0, transition:"easeOutBounce" } ); if (sec % 10 == 0) { upperSec.alpha = 0; upperSec.y = upperSec.y - 10; Tweener.addTween(upperSec, { time:0.5, y:yPosition, alpha:1.0, transition:"easeOutBounce" } ); } if (sec == 0) { lowerMin.alpha = 0; lowerMin.y = upperSec.y - 10; Tweener.addTween(lowerMin, { time:0.5, y:yPosition, alpha:1.0, transition:"easeOutBounce" } ); if (min % 10 == 0) { upperMin.alpha = 0; upperMin.y = upperMin.y - 10; Tweener.addTween(upperMin, { time:0.5, y:yPosition, alpha:1.0, transition:"easeOutBounce" } ); } if (min == 0) { lowerHour.alpha = 0; lowerHour.y = lowerHour.y - 10; Tweener.addTween(lowerHour, { time:0.5, y:yPosition, alpha:1.0, transition:"easeOutBounce" } ); if (hour % 10 == 0) { upperHour.alpha = 0; upperHour.y = upperHour.y - 10; Tweener.addTween(upperHour, { time:0.5, y:yPosition, alpha:1.0, transition:"easeOutBounce" } ); } } } } upperHour.x = 0; lowerHour.x = upperHour.x + upperHour.width; upperMin.x = lowerHour.x + lowerHour.width; lowerMin.x = upperMin.x + upperMin.width; upperSec.x = lowerMin.x + lowerMin.width; lowerSec.x = upperSec.x + upperSec.width; preSec = now.getSeconds(); } private function iniTextField(textField:TextField,font:String,size:Number,color:Number):void { textField.defaultTextFormat=new TextFormat(font, size, color); textField.autoSize = TextFieldAutoSize.LEFT; textField.selectable = false; addChild(textField); } } } Code Fullscreen Preview Fullscreen font size color getSeconds Math.min Tweener.addTween time TextField Date getHours getMinutes selectable String addEventListener defaultTextFormat TextFieldAutoSize.LEFT alpha autoSize width TextFormat