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)

Line Tool drawing using the AS3

22.7.2009, 14:51    Total views: 6943

Using this thoroughly explained, detailed action script 3 flash lesson, you will see how to draw any lines. You can use this lesson for some presentation or for some animation. Let's start!









Example:

Drag some lines below!



Step 1

Create a new flash document and select black color as background color.



Step 2


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

Step 3

Select the first frame of layer AS3 and go to the AS3 panel (F9). Then, enter this code inside the actions panel:

var drawing:Boolean = false;
this.graphics.lineStyle(1, 0xFFFFFF);
this.graphics.moveTo(mouseX, mouseY);
this.addEventListener(Event.ENTER_FRAME, onLoop, false, 0, true);
stage.addEventListener(MouseEvent.MOUSE_DOWN, onDown, false, 0,
true);
stage.addEventListener(MouseEvent.MOUSE_UP, onUp, false, 0, true);
function onDown(evt:MouseEvent):void {
drawing = true;
}
function onUp(evt:MouseEvent):void {
drawing = false;
}
function onLoop(evt:Event):void {
if (drawing) {
this.graphics.lineTo(mouseX, mouseY);
} else {
this.graphics.moveTo(mouseX, mouseY);
}
}

That's it

Test your movie (Ctrl+Enter) and start drawing!

Download source file (.fla)

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: 166040

3. Photo slide show
Total views: 153641

4. High-tech city animation
Total views: 151459

5. Special Picture Effect
Total views: 146246

Related links