Toxiclab.org

Friction effect in flash

8.8.2009, 11:11
Submited in: Flash | Total Views: 9536

Using this thoroughly explained, detailed flash lesson, you will see how to create realistic friction effect using the action script code. Using this lesson, you will also learn how to convert any object into a Movie Clip Symbol, how to apply action script code on it and much much more!

Example:

Click on the photo below and hit your arrows key to see the Friction effect!




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 58 and click ok.

Step 2

Call the current layer object. Double-click on its default name (Layer 1) to change it. Press Enter once you have typed in the new name!

Step 3

Draw some circle shape, or import some picture of ball into a flash stage.

Step 4

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



Step 5

Select now the Selection Tool (V) and click once on the new made movie clip (object) to select it. After that, go to the AS panel (F9) and enter this code inside the actions panel:

onClipEvent (load) {
 power = 0.4;
 yspeed = 0;
 xspeed = 0;
 friction = 0.92;
}

onClipEvent (enterFrame) {
 if (Key.isDown(Key.LEFT)) {
  xspeed -= power;
 }
 if (Key.isDown(Key.RIGHT)) {
  xspeed += power;
 }
 if (Key.isDown(Key.UP)) {
  yspeed -= power;
 }
 if (Key.isDown(Key.DOWN)) {
  yspeed += power;
 }
 xspeed *= friction;
 yspeed *= friction;
 _y += yspeed;
 _x += 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