Adobe Photoshop Tutorials | Flash Tutorials | 3D Studio Max Tutorials | Website Templates | Webmaster Forum
Home Photoshop | Flash | 3D | Tools | Articles | Directory | Links Link to Us | Contact Us
- Flash Tutorials - Rotating Objects in Flash - By: Chad Freiling

Rotating Objects in Flash

- Part 1
First off, Start a new Flash file.

For this tutorial I created a Square and set it as an MC (Movie Clip). Name this MC square.

Select the newly create MC, and go to the ActionScript of the square and follow the insturctions below:

First thing is to add the function on which the script will start the rotation of the MC. So for this, we'll need to add an onClipEvent. And the movieEvent will be enterFrame. So when the we enter the frame that the mc is on, it will start the actionScript that is inside the onClipEvent. [ See code to the right, Should be what you have so far. ] onClipEvent (enterFrame) {

Next, We add the actionScript that will do the rotation. First we add a Varible to the code. This varible will store the information for the rotation. For this tutorial we'll use the letter 'i'.

The getProperty(); function is used to specify a target and a certian property. in this case, we use 'this' as are target and _rotation as are property. Normally when using the getProperty(); function you'll use the MC's Name. Which we have named our MC 'square'.

So the code can also looks like i = getProperty(square,_rotation);. but because the Code is on the MC the target can be named 'this'. Using 'this', lets the ActionScript know that its controling itself.

i = getProperty(this,_rotation);
So far, the Code should something like this: onClipEvent (enterFrame) {
     i = getProperty(this,_rotation);
Now we add the last Action to the code. For this part we use the setProperty(movieClip, property, value); function. This function allows us to manipulate the MC. In this instance we're wanting to manipulate the _rotation of the MC. Again, We use 'this' for the movieclip and _rotation for the property and i + 1 for the value. What i + 1 does is, i is set with the getPropery() function. And gets the current position of the MC's _rotation, Then adds 1 to it. setProperty(this,_rotation,i + 1);
So now our Full Code should look like this: onClipEvent (enterFrame) {
     i = getProperty(this,_rotation);
     setProperty(this,_rotation,i + 1);
Run the Code and Lets See what Happens... Don't forget to save!
Now Depending on how you have your fps (frames per second) set for the Flash Movie this should move somewhat slow. So lets change the 1 to lets say, 10.

Now, That Moves much Faster, No?
Depening on how fast you want the rotation to go depends on what you set the Number to. the Higher the Number the faster it goes.

So if you set it to i + -1, it will rotate backwards. i + -10, will rotate backwards and faster.

So, now you know how to use the _rotation property. Try using this method with other simple properties.

Home Copyright © 2003 - 2005, Tutorials Network. All Rights Reserved. | Advertise | Privacy Policy