Toxiclab.org

Rotation effect using the AS

11.8.2009, 22:2
Submited in: Flash | Total Views: 6940

In this tutorial, we're going to create a rotation effect using the Action Script code and arrows key on the keyboard. You can use this effect for some presentation, or for some flash banner. Let's start!



Example:

Use the arrows key on the keyboard to move the object!



Step 1

Create a new flash document. Press Ctrl+J key on the keyboard (Document Properties) and set the dimensions of your document as whatever you like. Select any color as background color. Set your Flash movie's frame rate to 35 and click ok.



Step 2


Draw or import any object which you like to use for this lesson.

Step 3

While the object is still selected, hit F8 key (Convert to Symbol) to convert it into a Movie Clip Symbol.



Step 4

Select the Selection Tool (V) and click once on the object to select it. After that, go to the action script panel (F9) and enter this code inside the actions panel:

onClipEvent (load) {
 speed = 0.62;
 yspeed = 0;
 xspeed = 0;
 friction = 0.85;
 gravity = 0.1;
 thrust = 0.65;
 wind = 0.10;
}
onClipEvent (enterFrame) {
 if (Key.isDown(Key.LEFT)) {
  xspeed -= speed;
 }
 if (Key.isDown(Key.RIGHT)) {
  xspeed += speed;
 }
 if (Key.isDown(Key.UP)) {
  yspeed -= speed*thrust;
 }
 if (Key.isDown(Key.DOWN)) {
  yspeed += speed*thrust;
 }
 xspeed += wind;
 xspeed *= friction;
 yspeed += gravity;
 _y += yspeed;
 _x += xspeed;
 _rotation += xspeed;
}

That's it!

Test your movie and enjoy!

Download example

Are you a website owner?
Click here to register and submit your tutorials!

Browse by category


Most popular tutorials