|
||||||
|
||||||
Flash Tutorial - Animated Clock

Free
Tutorial
Step 3 << Previous • Intro 1 2
3 • >>
|
Step Three: The ActionScript MC Frame 3
Note: You should still be Editing inside the Movie Clip: ActionScript MC
Note: If you wanted the animation to play at a slower speed you could place the code on a frame further down the timeline, such as Frame 10 etc.
// Set the target to this
tellTarget ("..") {
// Get the location of the mouse and set the clock location accordingly
yClock = _ymouse+clockOffsetY;
xClock = _xmouse+clockOffsetX;
// Set the date location
yDate[0] = yDate[0]+(yClock-yDate[0])*easingRate;
xDate[0] = xDate[0]+(xClock-xDate[0])*easingRate;
// For the length of the variable D set the date center starting location and easing rate
for (i=1; i<D.length; i=i+1) {
yDate[i] = yDate[i]+(yDate[i-1]-yDate[i])*easingRate;
xDate[i] = xDate[i]+(xDate[i-1]-xDate[i])*easingRate;
}
// Set the hands of the clock center starting location and easing rate
yHand[0] = yHand[0]+(yClock-yHand[0])*easingRate;
xHand[0] = xHand[0]+(xClock-xHand[0])*easingRate;
// For the length of the variable F set the hands center starting location and easing rate
for (i=1; i<F.length; i=i+1) {
yHand[i] = yHand[i]+(yHand[i-1]-yHand[i])*easingRate;
xHand[i] = xHand[i]+(xHand[i-1]-xHand[i])*easingRate;
}
// Get the system date
var time = new Date();
// Get the seconds from the system date
var seconds = time.getSeconds();
// Get the minutes from the system date
var minutes = time.getMinutes();
// Get the hours from the system date
var hours = time.getHours();
// Set the angle for the seconds
var secondsAngle = 3.141593*2*(seconds/60-1.250000);
// Set the angle for the minutes
var minutesAngle = 3.141593*2*((minutes+seconds/60)/60-1.250000);
// Set the angle for the hours
var hoursAngle = 3.141593*2*((hours+minutes/60)/12-1.250000);
// Set up the clock face numbers with some maths
for (i=0; i<F.length; i=i+1) {
var faceSprite = eval("chFace"+i);
a = (i*FaceDeltaAngle-90)*3.141593/180;
faceSprite._y = yHand[i]+clockDiameter*Math.sin(a);
faceSprite._x = xHand[i]+clockDiameter*Math.cos(a);
}
// Set the location for the hour hand based on some maths
for (i=0; i<H.length; i=i+1) {
var hoursSprite = eval("chHours"+i);
hoursSprite._y = yHand[i]+HandY+i*HandHeight*Math.sin(hoursAngle);
hoursSprite._x = xHand[i]+HandX+i*HandWidth*Math.cos(hoursAngle);
}
// Set the location for the minute hand based on some maths
for (i=0; i<M.length; i=i+1) {
var minutesSprite = eval("chMinutes"+i);
minutesSprite._y = yHand[i]+HandY+i*HandHeight*Math.sin(minutesAngle);
minutesSprite._x = xHand[i]+HandX+i*HandWidth*Math.cos(minutesAngle);
}
// Set the location for the second hand based on some maths
for (i=0; i<S.length; i=i+1) {
var secondsSprite = eval("chSeconds"+i);
secondsSprite._y = yHand[i]+HandY+i*HandHeight*Math.sin(secondsAngle);
secondsSprite._x = xHand[i]+HandX+i*HandWidth*Math.cos(secondsAngle);
}
// Set the circular rotation of the date around the clock face with some maths
for (i=0; i<D.length; i=i+1) {
var dateSprite = eval("chDate"+i);
dateSprite._y = yDate[i]+clockDiameter*1.500000*Math.sin(dateRotation+i*DateDeltaAngle*3.141593/180);
dateSprite._x = xDate[i]+clockDiameter*1.500000*Math.cos(dateRotation+i*DateDeltaAngle*3.141593/180);
}
// Set the date rotation speed
dateRotation = dateRotation-dateRotationStep;
}
// Replay the code and update the code to show the new time from last time it was checked
gotoAndPlay(2);
Note: the ActionScript is complete but it needs to be placed inside the Clock Movie Clip.
Note: You should find your Letter X Movie Clip inside the Clock MC.
That's it! Easy Hey?
|
Step 3 << Previous • Intro 1 2
3 • >> |
Why not try out webwasp's new community. Meet new people, find friends in your area: Webwasp Mates & Dates
•
37007 visitors to this page since
Jan 05•
|
|
|
All material on this site is protected under international copyright © law. DO NOT reproduce any material from this site without written permission. Please ask as permission is often granted.
|