Flash tutorials
Home 3D (2) Actionscripting (65) Animation (100) Audio (4) Drawing (7) Full flash sites (4) Getting Started (15) Navigation (25) Special Effects (52) Text Effects (38)

Drawing shapes using the Action Script code

9.4.2009, 21:2    Total views: 7332

In this thoroughly explained, detailed lesson, I will show you how to draw any shape using a little action script code. This lesson is created on a simple way. You just have to copy and paste my action script code to make a shape. Let's start!

Action Script 2

Step 1

Create a new Flash document. Go to the Action Script Panel (F9). Copy and paste code below to get a blue rectangle.

this.createEmptyMovieClip("rectangle_mc", 1);
with(rectangle_mc){
lineStyle(6, 0x003399, 100, true, "normal", "rectangle", "bevel", 1);
moveTo(0, 0);
lineTo(150, 0);
lineTo(150, 70);
lineTo(0, 70);
lineTo(0, 0);
_x=80;
_y=80;
}



Copy and paste code below to get a red line:

this.createEmptyMovieClip("line_mc", 1);
with(line_mc){
lineStyle(2, 0x990000, 100, true, "normal", "square", "miter", 1);
moveTo(0, 0);
lineTo(150, 0);
_x=180;
_y=165;
}



Action Script 3

Copy and paste code below to get a green square:

var square:Sprite = new Sprite();
addChild(square);
square.graphics.lineStyle(3,0x336600);
square.graphics.beginFill(0x336600);
square.graphics.drawRect(50,100,100,100);
square.graphics.endFill();
square.x = stage.stageWidth/3-square.width/3;
square.y = stage.stageHeight/3-square.height/3;



Copy and paste code below to get a black circle with red border:

var myCircle:Shape = new Shape();
myCircle.graphics.lineStyle(2, 0xff0000);
myCircle.graphics.beginFill(0x000000);
myCircle.graphics.drawCircle(130, 220, 80);
addChild(myCircle);
myCircle.graphics.endFill();



That's it!

Enjoy!

Have questions about this tutorial?
Visit our friendly Community Forums!
Digg it! Add this tutorial to del.icio.us! Furl it! Add this tutorial to reddit! Spurl it! Add this tutorial to technorati!

Top tutorials

1. Advanced full flash site - Part 1
Total views: 221536

2. Water effect
Total views: 166041

3. Photo slide show
Total views: 153641

4. High-tech city animation
Total views: 151459

5. Special Picture Effect
Total views: 146247

Related links