ActionScript 3.0 Lesson 12: Create a Real Clock in Flash Using Sytem Date and Time

Mon, Aug 10, 2009

ActionScript

This movie requires Flash Player 9

I know it is fast, you can always stop the player, or mail questions…

Music: Pink Floyd Instrumental.

DOWNLOAD THIS TUTORIAL TO YOUR HARD DRIVE
DOWNLOAD THE SOURCE FLA FILE

CLICK HERE FOR A COMPLETE ACTIONSCRIPT 3.0 FLASH TIMER AND TIME CARTOON SMART TUTORIAL

HERE IS THE SOURCE CODE:

// Flash Actionscript 3.0 Clock
// by Avraham Saltoun.
// www.say-web.com
// FREE TO USE COPY and DISTRIBUTE!

// Let’s create the timer and the
// Date variable…

var myTimer:Timer = new Timer(1000);
var myDate:Date = new Date;

// Let’s create the time variables…

var mySeconds:int = new int;
var myMinutes:int = new int;
var myHours:int = new int;

myTimer.start();
myTimer.addEventListener(TimerEvent.TIMER, UpdateHands);

//The Function below will happen every second,
// indefinitely

function UpdateHands (e:TimerEvent):void //returns no value!
{

// In action script by default
// a new date has the current
// timestamp assigned

myDate = new Date;

// Hour Variables

mySeconds = myDate.getSeconds();
myMinutes = myDate.getMinutes();
myHours = myDate.getHours();

// Check if it is afternoon

if (myHours < 12 ) {myHours = myHours - 12;}

//The names have to be IDENTICAL
// to the instances created!!

SecondHand.rotation = (mySeconds * 6);
MinuteHand.rotation = (myMinutes * 6);
HourHand.rotation = (myHours * 30) + (myMinutes*0.5);

//The additional rotation in order to small
//advance to the next hours....

trace (myDate);
}

Related Articles:

, , , , , , , , , , , , , , , , , ,

Comments are closed.

My name is Avraham Saltoun, and I live in Jerusalem, Middle East. I am currently on my mid  40's and I am a computer programming technician. Here you will find over one hundred quality video tutorials on Actionscript, and yes, I give online support for aspiring programmers, and pros as well, sharing screen on skype and delivering source code by email, click the button for live flash actionscript support now!

 
oDesk Certified Action Script Programmer
oDesk Certified Adobe Flash CS3 Designer
oDesk Certified Adobe Photoshop 6.0 Designer
Skype Me™!

$7.49 .Com! Score Savings Cartoon Smart Tutorials


839
Unique Visitors
Previous 30 Days
Powered By Google Analytics