Developing Webs logo
Google
Web DW-Main DW-Photoshop
Visit the message board for solutions or post a question Check out the Classes offered for free at Developing Webs Voice Chat submit a tutorial, resources, article, font for publication consideration and earn a one way link back to your site Get more specifics about the Developing Webs Voice chat room and its room members View the current news at Developing Webs alternative sites which are resources for your d3evelopment needs Join Developing Webs Chat Link to us on your web page to help support this resource! Check out Developing Webs At yahoo groups! Developing Webs Home Adobe Photoshop Tutorials Macromedia Flash Tutorials Jasc Paint Shop Pro Tutorials Adobe Illustrator Animation basics Some Basic PHP tutorials Perl Tutorials HTML Tutorials Cascading Style Sheets javascript Front Page Tutorials Macromedia Dream Weaver Tutorials dreamweaver Publishing your site, FTP, ChMod, Promotions
RSS Newsfeed
for your site
DW News
Calendar
DW Forum
Right click on button and copy shortcut

Add to My Yahoo!

Reminder
Remember to book mark this site!



Request a Tutorial

A Clock Face

A lesson in EnterFrame Clip Events

You will need the this file to script your clock.

1. Open your movie file and review the components. There is one moive clip on the stage called hands. inside the clock movie clip are three separate layers, one for each of the hands on the clock. Each movie clip has an instance name, indicating the type of hand. We have secondhand_mc, minutehand_mc, and hourhand_mc.

2. Click back to your main stage and click on the hands movie clip to highlight it. We are going to put the hand movement scripts on this movie clip as a clip event, using the event enterFrame. The enterFrame event calls for the script to be played at the frame rate. The frame rate of this movie is 12 frames per second, therefore on script in an onClipEvent(enterFrame){} event handler would be played 12 times a second as long as the movie clip it is attached to remains on stage.

Open the actions panel with the hands movie clip highlighted. type in the framework for the onClipEvent with the event of enterFrame. Type in onClipEvent( and select the enterFrame from the drop down box. Finish the script by closing the parentheses ) and add a set of curly brackets {}.

onClipEvent(enterFrame){
}

3. We will put in the actions to rotate each of the hands by a factor equal to the previous rotation value plus a factor, determined be the frame rate. Add the folloring lines to the event handler as action lines for when the event occurs. Place them between the curly brackets (braces).

Click at the end of the open curly bracket(open brace). Hit your enter key to go to the next line. Click the target button. Select the second hand_mc and set the path to relative. Click ok.

Add a period to the actionscript. A new drop down appears. select the property _rotation.

Add the operator = . Type in the word Number (case sensitive). Open a parenthesis and target the same movie clip. Add a period, and select _rotation from the list. Close parenthesis and use the plus operator. Add 1/2. End your script line with a semicolon.

onClipEvent(enterFrame){
this.secondhand_mc._rotation = Number(this.secondhand_mc._rotation) + (1/2);
}

4. Add scripts to change the rotation property of the minute hand and the hour hand in the same way, changing the increment to 1/120 for the minute hand, and 1/1440 for the hour hand.

The resulting script applied to your movie clip should look like this:

onClipEvent(enterFrame){
this.secondhand_mc._rotation = Number(this.secondhand_mc._rotation) + (1/2);
this.minutehand_mc._rotation = Number(this.minutehand_mc._rotation) + (1/120);
this.hourhand_mc._rotation = Number(this.hourhand_mc._rotation) + (1/1440);
}

4. Click the blue check mark at the top of the actions panel to check your syntax to make sure the script is written correctly. Then test your movie.

Remember hour hands move very slowly. If you want to see the clock operate faster, try save the movie at a much faster frame rate.

 



"Building The Web Into a Nicer Place -- One Site At A Time"
Developing Webs Group Copyright © 2001-2024 All Rights Reserved
Privacy and Legal