Download Tutorial as PDF file.

For every planet movie clip in your library you will have to set Linkage parameters like image shows. For class parameter use different names. I have only two planets in this example, but you can use more if you like. My planets classes are PlanetSmall and PlanetBig.

Create new ActionScript file in same folder as your StarSystem.fla, name it StarSystem.as and open it for editing. Now the code.
First we import some libraries:
package
{
import flash.display.Sprite;
import flash.events.Event;
import flash.display.Stage;
We define our class:
public class StarSystem extends Sprite {
private var p1:PlanetSmall;
private var p2:PlanetBig;
Next we define two variables to represent center of the stage:
private var xCenter:Number = stage.stageWidth/2;
private var yCenter:Number = stage.stageHeight/2;
private var angle:Number = 20;
private var xRadius:Number = 250;
private var yRadius:Number = 150;
private var speed:Number = .008;
private var _angle:Number = -45;
private var _xRadius:Number = 100;
private var _yRadius:Number = 65;
private var _speed:Number = .01;
All these variables are something you need to test for yourself to find right numbers.
Then we define main method,
public function StarSystem() {
init();
}
note how main method must be declared as public not private. Init function goes like this:
private function init():void {
p1 = new PlanetSmall();
addChild(p1);
p2 = new PlanetBig();
addChild(p2);
addEventListener(Event.ENTER_FRAME, onEnterFrame);
}
public function onEnterFrame(event:Event):void {
p1.x = xCenter + Math.sin(angle) * xRadius;
p1.y = yCenter + Math.cos(angle) * yRadius;
p1.scaleX = p1.scaleY = p1.y/400;
p1.alpha = p1.scaleX*2;
angle += speed;
p2.x = xCenter + Math.sin(_angle) * _xRadius;
p2.y = yCenter + Math.cos(_angle) * _yRadius;
p2.scaleX = p2.scaleY = p2.y/300;
p2.alpha = p2.scaleX*1.2;
_angle += _speed;
}
}
}
We also set alpha as function of scale which is nice trick to use. Feel free to play with these numbers and see what suits your needs. Last line of the code changes angle of the planets as function of defined speed and this happens every new frame. Test your star system.
I hope you will make better looking rotating planets , some supernovas, stars and galaxies on background, animated Sun, maybe some starship or even planets with moons orbiting around them! When you do that, send me the link, I would like to see your creation.
Thanks for your time.
*_*









