Drawing program
Code Actionscript 2.0
Frame action
createEmptyMovieClip("drawing", 1);
drawing.lineStyle(0, 0x000000, 100);
onMouseDown = function () {
mousepressed = 1;
};
onMouseUp = function () {
mousepressed = 0;
};
onEnterFrame = function () {
if (mousepressed == 1) {
drawing.lineTo(_xmouse, _ymouse);
} else {
drawing.moveTo(_xmouse, _ymouse);
}
};
Code Actionscript 3.0
addEventListener(Event.ENTER_FRAME, enterFrame); stage.addEventListener(MouseEvent.MOUSE_DOWN, press); stage.addEventListener(MouseEvent.MOUSE_UP, release); var drawing:MovieClip = new MovieClip(); drawing.graphics.lineStyle(1, 0x000000, 1); this.addChild(drawing); var mousepressed=0; function press(e:MouseEvent) { mousepressed = 1; } function release(e:MouseEvent) { mousepressed = 0; } function enterFrame(e:Event) { if (mousepressed == 1) { drawing.graphics.lineTo(mouseX, mouseY); } else { drawing.graphics.moveTo(mouseX, mouseY); } }
Description
This is a drawing program, in which allows the user to lift the (imaginary) pen from the paper, as the line is only drawn when the mouse is pressed. The state of the mouse is stored in the variable mousepressed. With the condition if (mousepressed == 1), this state status is checked in every step. If the mouse is pressed, the command lineTo draws a line, otherwise the command moveTo just moves the pen, without drawing.
related to: Draw line
Download
Right click: Flashfile AS 2.0 | Flashfile AS 3.0 | SWF-File