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: work2survive
» Title: Girl Walking 1kb
» Description: Walking girl, animation just takes 1kb, using high heels shoes, and fashion model attitude.
Featured Sound Loops
Image for equalize

Audio Player

» Author: BoxCat
» Title: CPU Talk
» Description: From the cyberpunk RPG, "Nameless: the Hackers" Completely Free to use! Keywords: edm hip hop rap electronic mysterious mission hacking chase exciting spy ios ambient chilling love happy sad angry suspense
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: nathan
» Description:

A recorded sound of the Dimensional Fork Gate.