Getting started with Actionscript 3.

Part One - Creating a simple program
Milan Toth
Milan Toth is the Chief Flash Developer of Jasmin Media Group, he created one of the world's biggest flash media server system. He loves Eclipse and OS X, AS3 and JAVA, sci-fi and horror, metal and electronic.
Let's start with something easy, create a simple orange circle first. Open Flex Builder, File menuitem -> New -> Actionscript Project, type FirstCircle for name, and press Enter.
There should be a Navigator view on the left, showing our project files, and a big editor view on the right, showing FirstCircle.as, and a basic AS3 code :
package
{
import flash.display.Sprite;
public class FirstCircle extends Sprite
{
public function FirstCircle( )
{
}
}
}
This is our main class, the "entering point" of our program. It is in the root package, and it is extended from the Sprite class, because AVM2 needs something visible for main class, we cannot create non-visible AS3 programs.
Let's compile and run this class. Run menuitem -> Run, and your default browser appears with a big blueish grey screen, and nothing happens. That is good, because we didn't write anything in the main class yet.
So, let's draw an orange circle. We need a displayobject with graphical abilities, there are three of this kind: the Shape, the Sprite and the MovieClip. Because we don't need a timeline and child display objects, we use the simplest class, the Shape.
package
{
import flash.display.Sprite;
import flash.display.Shape;
public class FirstCircle extends Sprite
{
public function FirstCircle()
{
// creating a new shape instance
var circle:Shape = new Shape( );
// starting color filling
circle.graphics.beginFill( 0xff9933 , 1 );
// drawing circle
circle.graphics.drawCircle( 0 , 0 , 40 );
// repositioning shape
circle.x = 40;
circle.y = 40;
// adding displayobject to the display list
addChild( circle );
}
}
}
For tips on how to use Shape or DisplayObject's graphics use Flex Builder's built-in language reference, or Adobe's LiveDocs. The other important thing is the last row "addChild". DisplayObjects are no longer depth-organized, as in previous versions of actionscript, we have to attach them to displayobject containers instead to make them visible. They still have a .visible property, but that is a little bit different.
Spread The Word
Article Series
This article is part 1 of a 2 part series. Other articles in this series are shown below:
-
Getting started with Actionscript 3.


