Toxiclab.org

Orbiting animation using the AS

30.3.2009, 13:45
Submited in: Flash | Total Views: 13599

Using this thoroughly explained, detailed and quickly flash lesson, I will explain to you how to create orbiting animation using a little AS code. Let's start!






Example:




Step 1

First, save the image of earth below!





Step 2


Create a new flash document. Press Ctrl+J key on the keyboard (Document Properties) and set the width of your document to 430 pixels and the height to 350 pixels. Select black as background color. Set your Flash movie's frame rate to 15 and click ok.



Step 3

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

Step 4

Choose now File > Import > Import to stage (Ctrl+R) and import the image of earth that you saved in step 1!

Step 5

While the image is still selected, go to the Align Panel (Ctrl+K) and do the following:

1. Make sure that the Align/Distribute to Stage button is turned on,
2. Click on the Align horizontal center button and
3. Click the Align vertical center button.



Step 6

While the image of earth is still, still selected, press F8 key (Convert to Symbol) to convert it into a Movie Clip Symbol.



Step 7

While the new made Movie Clip (earth) is still selected, go to the Properties Panel below the stage. On the left side, You will find the Instance name input field there. Call this Movie Clip earth. See the picture below!



Step 8

Create now a new layer above the layer earth and name it object. After that, using the flash tools for drawing, draw any object.

Step 9

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



Step 10

After that, place the object on the position like it is shown on the picture below!





Step 10

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

onClipEvent(load){
    angle=0
    mainDistance=140
}
onClipEvent(enterFrame){
    angle+=5
    xDistance=Math.sin(angle * Math.PI/180)*mainDistance
    yDistance=Math.cos(angle * Math.PI/180)*mainDistance
    xDisCalculated=_root.earth._x-xDistance
    yDisCalculated=_root.earth._y-yDistance
    this._x=xDisCalculated
    this._y=yDisCalculated
}

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