First time here? First time here? Newsletter Signup Newsletter
Login | Register | 651326 Members and growing!
Search tutorials
Author: Jesse

Step 1: Letting the user draw

First thing's first. Make a new Flash document and call it drawing AI. Then, type the following code in the actions panel.

stop()
lines = {}
_root.createEmptyMovieClip("pen", 10)
pen.lineStyle(1, 000000, 100)

This code simply stops the move and creates an object called lines. Then, it creates a movie clip called pen and sets it up so it can draw with the lineStyle method. Now, let's look at the code that lets you draw.

_root.onMouseDown = function(){
	drawing = true
	pen.moveTo(_xmouse, _ymouse)
	segments += 1
	name = "line"+segments
	lines[name] = ["break", _xmouse, _ymouse]
}
_root.onMouseMove = function(){
	if(drawing==true){
		pen.lineTo(_xmouse, _ymouse)
		segments += 1
		name = "line"+segments
		lines[name] = [_xmouse, _ymouse]
	}
}
_root.onMouseUp = function(){
	drawing = false
}

This is alot of code, but it's pretty simple. It makes it so that when you click the movie, drawing is set to true ans then pen moves to the mouse's x and y positions. Then it adds one to the segments variable, and creates an array in the lines object, containing the string "break", the x position of the mouse, and the y position of the mouse. This code makes sure that when the drawing is being re-drawn by the computer, it knows to take a break so it can move to the new position, instead of constantly drawing lines. Then, if the mouse is moving, the game checks to see if drawing is true. If it is, the pen movie clip draws a line to the mouse, and adds one to the segments variable. We then create an array in lines containing the mouse's position, but we do not include "break" so the computer knows we are only drawing a line. Finally, when the mouse is released, drawing is set to false. Now, create a movie clip with a red circle and a black text field saying "ok". Put this in the first frame and type the following code into the actions panel for the ok movie clip.

on(press){
	_root.gotoAndStop(6)
}

What this code does is it simply sends the root timeline to the sixth frame when the movie clip is pressed.

» Level Intermediate

Added: 2004-12-24
Rating: 8 Votes: 7
(10 being the highest)
» Author
Just started working with Flash.
» Download
Download the files used in this tutorial.
» Forums
More help? Search our boards for quick answers!

Comments

  • There are no comments yet. Be the first to comment!

  • You must have javascript enabled in order to post comments.

Leave a Comment
  • Your email address will not be published. All fields are required.
Featured Flash FLA
» Author: work2survive
» Title: Girl Walking 1kb
» Description: Walking girl, animation just takes 1kb, using high heels shoes, and fashion model attitude.
Featured Sound Loops
Image for equalize

Audio Player

» Author: BoxCat
» Title: CPU Talk
» Description: From the cyberpunk RPG, "Nameless: the Hackers" Completely Free to use! Keywords: edm hip hop rap electronic mysterious mission hacking chase exciting spy ios ambient chilling love happy sad angry suspense
Latest Font
» Author: Fábio FAFERS
» Description: I created this font for free use. Everyone can apply it in personal or business texts. Its free, but I want to be communicated in case of business use. Donations are accepted to keep the project of free fonts alive! Thank you all
Featured Sound Fx
Image for equalize

Audio Player

» Author: nathan
» Description:

A recorded sound of the Dimensional Fork Gate.