Flash tutorials
Home 3D (2) Actionscripting (63) Animation (90) Audio (4) Drawing (7) Full flash sites (4) Getting Started (15) Navigation (25) Special Effects (50) Text Effects (17)

Object spin

16.10.2006, 21:0    Total views: 50278

This tutorial will show you how to rotate any object on click, using the Action Script code. For this tutorial I will use bmw logo.Using this lesson, you will also learn how to convert any object into a Movie Clip Symbol, how to create instance name and much more! Let's start!

Example:



Step 1

Create a new flash document, press Ctrl+J on the keyboard (Document Properties) and set Width to 300 and Height to 250px. Frame rate set to 40fps (Frames per Second).





Step 2


Open any object that you want to spin, or draw some object. For this example I will draw bmw logo. See the picture below.



Step 3

Select that object and press F8 on the keyboard (Convert to Symbol) to convert it into a Movie Clip.



Step 4

While your new made Movie Clip (object) is still selected, open the Properties Panel (Ctrl+F3), and under  type object. See the picture below!



Step 5

Insert a new layer, take the Text Tool (T) and type somewhere on the stage SPIN. Look at the picture below!



Step 6

Insert a new layer and name it invisible button. Then, take the Rectangle Tool (R) and draw a "rectangle" on the place where you have wrote SPIN.

Step 7

While your "rectangle" is still selected, press F8 on the keyboard (Convert to Symbol) and convert it into a Button.

Step 8

Double click on a new made button, or choose right click and Edit in Place.



Step 9

Then, do like it is shown on the picture below.



Step 10

Go back on main scene ( Scene1 ), select the button, open the Action Script Panel (F9), and paste this script:

on(press){
object.spinning = true
object.spin = 12 + Math.random()*20
object._rotation = object._rotation = 0
}

Step 11

Select the object (in my example bmw logo) open the Action Script Panel (F9) and paste this script:

onClipEvent(enterFrame){
if (spinning){
if (spin <= 0){
spinning = false
rot = (_rotation < 0) ? 180 + _rotation : _rotation
_root.youSpunA = Math.floor(16 * rot/180)+1
}else{
_rotation += spin -= .25
_parent.wheel._rotation = -_rotation
}
}
}

We're done!

Cheers!

Download source file (.fla)

Have questions about this tutorial?
Visit our friendly Community Forums!
Digg it! Add this tutorial to del.icio.us! Furl it! Add this tutorial to reddit! Spurl it! Add this tutorial to technorati!

Top tutorials

1. Advanced full flash site - Part 1
Total views: 205311

2. Water effect
Total views: 152387

3. High-tech city animation
Total views: 139793

4. Special Picture Effect
Total views: 138396

5. Photo slide show
Total views: 138123

Related links