website promotion banner
eturnkeys
Your Ad Here
Flash & Swish  Home Flash & Swish Flash Tutorials Rotating Objects in Flash
rss

Rotating Objects in Flash

Author: Chad Freiling More by this author


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.

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.



Author's URL: www.newtutorials.com

Rate this Material: Bad 1 2 3 4 5 Excellent
print this page tell a friend subscribe to newsletter subscribe to rss

Read/Add comments to "Rotating Objects in Flash"

comments  kingwiqid January 11, 2007 says:
Rotating Objects in Flash
I've have seen a couple tutorials for rotation and instead of just rotating , the MC pivots on its corner (instead of the center) and is no longer on the same x axis once it has rotated 360 degrees. ( try this with a BOX MC) I discovered that you have to move the pivot point to the center of the MC for it to smoothly rotate. I have noticed that none of ther tutorials i have red have adressed this issue - and if you dont know it could be frustrating watching your charactor jump up a line ever time you turn the opposit direction. Just thought someone could benefit from the info - it should probably be added to the tut.