First time here? First time here? Newsletter Signup Newsletter
Login | Register | 651326 Members and growing!
Search tutorials
Author: Alan Wisternoff | Website:

Step Four: The Revolving Movieclip

The movieclip I wanted to follow the needle is actually a dynamic textbox inside a movieClip. On the stage use the text tool to create a textbox. In the options choose dynamic, single line, dont check any of the checkboxes and embed any fonts you require. In the variable box add this:


Then select this textbox and convert it to a movieClip. It does not need an instance name. We will use an onClipEvent action to position this movieClip at the correct place. Now comes the maths!

We need to give the movieclip the coordinates (x,y) at the end of the needle. Seeing we have the angle (w) and the length of the needle (in my case 210 pixels) we can work out everything else with sin/cos. Use the grid to measure the length of your own needle. The bottom right has the formulae if you are unfamiliar with these trigometric functions. One thing we need to do now is convert our angle (w) from degrees to radians, which we must use as the angle in these formulae. Back on the main timeline with the other variables add this:

radian = Math.PI/180*(w);

This is just a formula to do the conversion. Select the textbox movieclip and add this code:

onClipEvent (enterFrame) {
 this._x = 210*(Math.sin(_root.radian))+_root.needle._x;
 this._y = 210*(Math.cos(_root.radian))+_root.needle._y;

Using the top line of code which generates the x coordinate as an example I will explain the maths. If the sine of an angle is the opposite over the hypotenuse that would mean

sine(radian) = opposite/210

therefore the opposite (x coordinate) = 210 * sin(radian), which you can see is what we have in the code. At the end we have added

+ _root.needle._x;

as we are working out our angles from the needles registration point. So as the angle w increases, our x,y coordinates will be constantly updated and the movieclip will track around the needles outer edge. If you test the movie now you will see everything working apart from one small detail. The movie clip is tracking in a counerclockwise direction, opposite to the needle!

» Level Intermediate

Added: 2003-05-19
Rating: 6.64 Votes: 33
(10 being the highest)
» Author
Cyclist, Snowboarder, Flash Designer Extrordinaire.
» Download
Download the files used in this tutorial.
» Forums
More help? Search our boards for quick answers!


  • There are no comments yet. Be the first to comment!

  • You must have javascript enabled in order to post comments.

Leave a Comment
  • Your email address will not be published. All fields are required.
Featured Flash FLA
» Author: Inocreato
» Title: RaiseTheBlocks
» Description: Raise all the blocks to win the game
Featured Sound Loops
Image for equalize

Audio Player

» Author: TomCat Carty
» Title: The Wood
» Description: Just a little game ending or it can maybe be looped. Recorders with music box and percussion to give the feel of well, I don't know, the woods? Free to use, just credit me. thank you
Latest Font
» Author: Fábio FAFERS
» Description: I created this font for free use. Everyone can apply it in personal or business texts. Its free, but I want to be communicated in case of business use. Donations are accepted to keep the project of free fonts alive! Thank you all
Featured Sound Fx
Image for equalize

Audio Player

» Author: Davisigner
» Description: Hmm... what to say about this one? It's reminiscent of the closing notes of the opening music from the Three Stooges done in a church organ style with a closing cymbal crash. I'll give this one away gratis, but feel free to check out my free loops and potential upcoming license-mandated ones over in the respective part of Flashkit.