| |
package
{
import flash.display.*;
import flash.events.*;
import flash.text.*;
import flash.utils.Timer;
public class clock_1 extends MovieClip
{
//timer
public static var theTimer:Timer = new Timer(1000);
//holds the speed of the sweeping hand
public static const rotationConstant:Number = 6;
//DAY text field
private var dayTF:TextField = new TextField;
//DATE text field
private var dateTF:TextField = new TextField;
//TIME text field
private var timeTF:TextField = new TextField;
//SECONDS text field
private var secondsTF:TextField = new TextField;
//AM/PM text field
private var ampmTF:TextField = new TextField;
//holds the number of hours
private var cHours:int = 0;
//holds the number of minutes
private var cMin:int = 0;
//holds the number of seconds
private var cSec:int = 0;
//holds textual month (first 3 letters)
private var monthThree:Array = new Array("Jan", "Feb", "Mar", "Apr",
"May", "Jun", "Jul", "Aug", "Sep", "Oct", "Nov", "Dec");
//holds textual day of the week, full text
private var dayFullText:Array = new Array("Sunday", "Monday", "Tuesday",
"Wednesday", "Thursday", "Friday", "Saturday");
//------------------------------------------------------------------------
public function clock_1()
{
init();
}
//------------------------------------------------------------------------
public function init()
{
//build the clock
make_clock();
//start clock. Run once a second
theTimer.addEventListener(TimerEvent.TIMER, set_clock);
theTimer.start();
}
//------------------------------------------------------------------------
public function set_clock(e:TimerEvent):void
{
var now:Date = new Date();
var minutes = now.getMinutes();
var seconds = now.getSeconds();
var hours = now.getHours();
var ampm:String;
//prepend zero for minutes and seconds
minutes = number_format(minutes);
seconds = number_format(seconds);
//determine AM or PM, set hours to non-military time
if (hours > 12)
{
hours = hours-12;
ampm = "PM";
}
else if (hours == 12)
{
ampm = "PM";
}
else
{
ampm = "AM";
}
//midnight hour, set to 12
if (hours == 0)
{
hours = 12;
}
//day text. eg: "Wednesday"
dayTF.text = dayFullText[now.getDay()];
//trace("today is " + dayTF.text);
//date text. eg: "Jan 31 2009"
dateTF.text = monthThree[now.getMonth()] +" "+ now.getDate()
+" "+ now.getFullYear();
//time text. eg: "10:35"
timeTF.text = hours+":"+ minutes;
//seconds text. eg: "22"
secondsTF.text = seconds;
//ampm text. eg: "AM"
ampmTF.text = ampm;
}
//------------------------------------------------------------------------
public function number_format(thisNum:int):String
{
var returnString:String;
if (thisNum < 10)
{
returnString = "0" + thisNum;
}
else
{
//cast int to string and return
returnString = String(thisNum);
}
return returnString;
}
//------------------------------------------------------------------------
public function make_clock()
{
var m1:TextFormat = new TextFormat();
m1.font = "Arial";
m1.bold = true;
m1.size = 12;
m1.color = 0xFFFFCC;
m1.align = "center";
//day text format
m1.size = 11;
m1.color = 0xFFCC00;
dayTF.defaultTextFormat = m1;
//dayTF.text = "Wednesday";
dayTF.width = 196;
dayTF.height = 60;
dayTF.wordWrap = false;
dayTF.x = -48;
dayTF.y = 3;
addChild(dayTF);
//date text format
m1.size = 12;
m1.color = 0xFFFFFF;
dateTF.defaultTextFormat = m1;
//dateTF.text = "Sept 29 2009";
dateTF.width = 180;
dateTF.height = 60;
dateTF.wordWrap = false;
dateTF.x = -40;
dateTF.y = 18;
addChild(dateTF);
//time text format
m1.color = 0xCCFFFF;
m1.size = 22;
timeTF.defaultTextFormat = m1;
//timeTF.text = "00:00";
timeTF.width = 180;
timeTF.height = 60;
timeTF.wordWrap = false;
timeTF.x = -45;
timeTF.y = 34;
addChild(timeTF);
//seconds text format
m1.color = 0xCCFFFF;
m1.size = 10;
secondsTF.defaultTextFormat = m1;
//secondsTF.text = "00";
secondsTF.width = 180;
secondsTF.height = 60;
secondsTF.wordWrap = false;
secondsTF.x = -10;
secondsTF.y = 36;
addChild(secondsTF);
//ampm text format
m1.size = 10;
m1.color = 0xFFFFFF;
ampmTF.defaultTextFormat = m1;
//ampmTF.text = "AM";
ampmTF.width = 180;
ampmTF.height = 60;
ampmTF.wordWrap = false;
ampmTF.x = -8;
ampmTF.y = 46;
addChild(ampmTF);
}
//------------------------------------------------------------------------
public function check_places(returnString:String):String
{
if (returnString.length < 2)
{
returnString = "0" + returnString;
}
return returnString;
}
//------------------------------------------------------------------------
//------------------------------------------------------------------------
}
}
|
|