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)