Create an Analog Clock Screensaver with Screentime for Flash

In this tutorial, I’ll show you how to build a stylish Analog Clock using ActionScript 3.0. We’ll use the resulting swf movie with Screentime for Flash to create a fully functional screensaver. Time for some fun..

Step 1: Brief Overview

Using the Date object and its properties, we’ll get the day, hours, minutes and seconds and use simple Math to display the obtained data in an Analog Clock. The updates will be handled by a Timer.

Also, you can add a Digital Clock to the Screensaver by following this FlashTuts+ Tutorial.

Step 2: Starting

Open Flash and create a new Flash File (ActionScript 3).

flash clock analog

Set the stage size to 640×400 and add a gray linear background (#DBDBDD, #B3B2B7). Screentime will automatically scale the movie to fullscreen so we don’t have to set the stage in the full resolution.

flash clock analog

Step 3: Clock Backgrounds

We’ll begin by creating the clock background.

Select the Oval Tool (O) and draw a 250×250 px circle and add a black linear background (#313131, #000000). Use the Gradient Transform Tool (F) to rotate the gradient to look like the following image:

flash clock analog

Create another circle, this time 248×248, with this linear gradient (#595959, #000000). Again, use the Gradient Transform Tool to rotate and adjust the gradient.

flash clock analog

Step 4: Numbers

Now let’s add numbers to our clock.

Select the Text Tool (T), pick a font of your choice and an appropriate size for the clock. I used Myriad Pro Regular, 22 Pt, #DDDDDD.

Write the numbers in one TextField for each and align them to the clock, this can be a little difficult without a reference, check the guides in the images.

Horizontal:

flash clock analog

Vertical:

flash clock analog

Step 5: Clock Hands

Time to create the clock hands.

Select the Poly Star Tool (click and hold in the Rectangle Tool Button), then in the Properties Panel click the Options button in the Tool Settings section. Change the number of sides to 3.

flash clock analog

Create a white 20×70 px triangle, convert it to a MovieClip and name it “hourHand”.

flash clock analog

Repeat this process for the minute hand, but change the height to 110 px. Remember to set the instance name to “minuteHand”.

flash clock analog

Select the Oval Tool and create a 26×26 px circle, convert it to a MovieClip and apply a filter as follows:

flash clock analog

For the second hand combine a 8×8 px circle and a 2×116 px rectangle. Fill them with this color #C90303.

flash clock analog

Step 6: ActionScript

Create a new ActionScript Document and save it as "Analog Clock.as".

flash clock analog

Step 7: Required Classes

These are the classes we will need:

package 
{
	import flash.display.Sprite;
	import flash.utils.Timer;
	import flash.events.TimerEvent;

Step 8: Extending the Class

We’re going to use Sprite specific methods and properties so we extend using the Sprite Class.

public class AnalogClock extends Sprite
{

Step 9: Variables

These are the variables we will use, explained in the comments.

/* A Date object used to get the time */

var date:Date = new Date();

/* Time Variables */

var hours:int = date.hours;
var minutes:* = date.minutes;
var seconds:* = date.seconds;

/* A Timer object that will handle the updates, executed every second */

var timer:Timer = new Timer(1000);

Step 10: Main Function

This function is executed when the class is loaded.

public function AnalogClock():void
{
	/* This code will set the clock hands in the correct position using the Date object data */

	hourHand.rotation = hours * 30 + (minutes * 0.5);//The Hour Hand rotates 30 degrees in 60 minutes, that's 0.5 degrees per minute
	minuteHand.rotation = minutes * 6;//The Minute rotates 6 degrees per minute, that's 360 degrees in 60 minutes - an hour
	secondHand.rotation = seconds * 6;//The Second Hand rotates 6 degrees per second, that is 360 degrees in 60 seconds - a minute
			
	timer.addEventListener(TimerEvent.TIMER, updateClock);
	timer.start();
}

Step 11: Update Function

This is the function that handles the Clock. It’s the same code from the first functions, just executed every second by the timer.

private function updateClock(e:TimerEvent):void
{
	date = new Date();

	hours = date.hours;
	minutes = date.minutes;
	seconds = date.seconds;

	hourHand.rotation = hours * 30 + (minutes * 0.5);
	minuteHand.rotation = minutes * 6;
	secondHand.rotation = seconds * 6;
}

Step 12: Document Class

Go back to the .fla file and in the Properties Panel add "AnalogClock" in the Class field to make this the Document Class.

flash clock analog

Step 13: Screentime for Flash

Screentime for Flash is a Screensaver creator tool, it’s fast and easy to use. You can get a trial version from the website. The demos are fully functional, except the screen savers they build expire one week after they are created. In this tutorial I’m using the Mac version so the Screensaver will be mac-only.

Step 14: Screensaver

Open Screentime and in the Content tab, select your file by clicking in the "…" button and browsing to the swf. Enter a name for your screensaver.

flash clock analog

Leave the Properties and Installer tabs as default and in the Publish tab name the installer, choose the options you need and click Build.

flash clock analog

When the build is complete, open the installer app and click install. Now you can choose your flashy screensaver from System Preferences.

Conclusion

You just learn how easy is to convert flash movies or applications to screensavers, explore the Screentime application and create your own!

Thanks for reading :)

  • André

    The thing i must like in your tutorials is the correct using of OOP, document classes and classes, and very well explained, i think you should write more and more here, congratulations and keep this great job…

    I would like from people what kind of tutorial they would like to see here? i am thinking about writing a new tutorial but i dont know what to write yet!

  • André

    Wow and just a tip for you i forgot to say… to get the minutes rotation more real too…

    the line minuteHand.rotation = minutes * 6 you can use:

    minuteHand.rotation = minutes * 6 + (seconds/360);

    so this will keep the minutes pointer running like the hours pointer, with a soft transition and not that hard transition, keeping it more realistic =)

    • André

      Ops, just a correction:

      minuteHand.rotation = minutes * 6 + (360/seconds);
      i´ve inverted the values

  • Pingback: Create an Analog Clock Screensaver with Screentime for Flash … at Flash Designers

  • Pingback: Create an Analog Clock Screensaver with Screentime for bFlash/b b…/b

  • Pingback: Create an Analog Clock Screensaver with Screentime for Flash … | PhotoShopped

  • MWeber

    Actually that’s a digital clock.

  • Pingback: Recopilacion de Tutoriales 4º - Pnardi

  • Pingback: Adobe Flash: 35+ Animated Trainings | oOrch Blog

  • u-sfi

    sorry, we can do this tutorial with flash cs2 portable,cs3 portable or complete

  • Hassan

    The short rss is broken…

  • Pingback: Down the Foxhole – Last Week on FlashTuts+

  • http://labs.dariux.com Dario Gutierrez

    I like it, and the code structure is awesome Carlos. Congratulations for this tut.

  • Pingback: Screentimeで時計スクリーンセーバーを作成する | DigiTechLog Dot Com

  • http://www.flashframer.com Flash Framer

    Very cool tut! Thanks!

  • http://mihail.gnetbg.net Mihail

    Nice tut Carloz! I only would remind to anyone to watch out about the registration points of the arrows in order to avoid strange behaviour when they are rotating :)

    Also you have to import flash.display.MovieClip in your class in order to get it working :)

  • Pingback: Screentimeで時計スクリーンセーバーを作成する | DigiTechLog Dot Com

  • Tirath

    Awesome tut
    Thanks so much for sharing it
    Keep up good work man
    God bless you :-)

  • marijan

    To make it work, I had to remove all instances from the stage in Clock.fla, set the linkage for each clip in the library, and then make instances of each component in AnalogClock.as.

    var date:Date = new Date();
    var secondHand:SecondHand = new SecondHand();
    var minuteHand:MinuteHand = new MinuteHand();
    var hourHand:HourHand = new HourHand();
    var clockFace:ClockFace= new ClockFace();

    Of course, the position of each had to be reset:
    secondHand.x = stage.stageWidth/2;
    secondHand.y = stage.stageHeight/2;

    addChild(clockFace);
    addChild(minuteHand);
    addChild(hourHand);
    addChild(secondHand);

  • Rodrigo

    Great tutorial! Congratulations!
    One thing I think you failed to mention is that your tutorial is to be changed the registration point of the hands at the time of its creation to the center and bottom.
    So hands may rotate properly.
    Two things that I think would be better to watch are:
    - Make the behavior of the minutes hand based on the seconds hand. In your example, the minute hand jumps 6 degrees every minute. It would be better if it behaved as you did with the hours hand, which changes according to the minutes hand.
    - Make the behavior of the seconds hand of the folowing more realistic with the use of some “tween”. For example, if the second hand is in 0s (pointing to 12) and then it will rotate 6 degrees, to look more realistic, the pointer could go to 7 or 8 degrees, then back to 5 degrees and then finally go to the 6 degrees. This behavior could be obtained using easing equation: “easeOutElastic”. As can be seen in this example: http://hosted.zeh.com.br/mctween/examples/clockHandsRight.swf
    Sorry for my english.

    • http://www.seansmyth.ie Sean Smyth

      Definitely something that I’m gonna try. This is a nice little project for me to mess around with.

  • George

    Thanks for sharing, very good

  • santhosh

    its very nice good job

  • http://www.design-hutt.com pankaj

    hey,thanks for the tutorial.I really need that.Can i use Adobe AIR instead of Screentime create installer.

  • http://www.design-hutt.com pankaj

    hey,thanks for the tutorial..i really need that.I just want to ask can i use Adobe AIR instead of Screentime to create installer

  • Pingback: uberVU - social comments

  • Pingback: screenTimeでスクリーンセーバー | web製作勉強日記

  • faron

    Thanx Carlos

  • http://atauldiit.wordpress.com/ Kazi Ataul Bari

    Create TUTORIAL ………….

  • http://atauldiit.wordpress.com/ Kazi Ataul Bari

    Great TUTORIAL ………….

  • Lee

    Hello Carlos, Thank you so much for your tutorial. Love your work!!

    However, I have some questions. How can I use 2 clocks in my flash website? It gets error when I put my second clock in a different scene or in a movie clip. Any idea? Please help. Thank you.

  • sunsh

    hi
    I tried this tutorial but can’t succeed.I followed all the steps but the time is not working !!!
    is there anything else i can do ?
    can u please help me ?
    I picked the analog clockCS3 and changed the background, then i copied the script and ran it . everything is fine but the clock is not working …. !!!
    plz help….
    Thanks in advance….

  • My

    mine says package can’t be nested… help please

  • Pingback: Corona SDK: Crea tu propia aplicación para iOS (I)