29.04.2013 Views

ACTIONSCRIPT 3.0

Create successful ePaper yourself

Turn your PDF publications into a flip-book with our unique Google optimized e-Paper software.

<strong>ACTIONSCRIPT</strong> <strong>3.0</strong> DEVELOPER’S GUIDE<br />

Working with dates and times<br />

/**<br />

* Displays the given Date/Time in that good old analog clock style.<br />

*/<br />

public function showTime(time:Date):void<br />

{<br />

// gets the time values<br />

var seconds:uint = time.getSeconds();<br />

var minutes:uint = time.getMinutes();<br />

var hours:uint = time.getHours();<br />

}<br />

// multiplies by 6 to get degrees<br />

this.secondHand.rotation = 180 + (seconds * 6);<br />

this.minuteHand.rotation = 180 + (minutes * 6);<br />

// Multiply by 30 to get basic degrees, then<br />

// add up to 29.5 degrees (59 * 0.5)<br />

// to account for the minutes.<br />

this.hourHand.rotation = 180 + (hours * 30) + (minutes * 0.5);<br />

First, this method extracts the values for the hours, minutes, and seconds of the current time. Then it uses these values<br />

to calculate the angle for each hand. Since the second hand makes a full rotation in 60 seconds, it rotates 6 degrees each<br />

second (360/60). The minute hand rotates the same amount each minute.<br />

The hour hand updates every minute, too, so it can show some progress as the minutes tick by. It rotates 30 degrees<br />

each hour (360/12), but it also rotates half a degree each minute (30 degrees divided by 60 minutes).<br />

Last updated 4/22/2013<br />

9

Hooray! Your file is uploaded and ready to be published.

Saved successfully!

Ooh no, something went wrong!