Internet Commerce

Partners & Affiliates

Developer Channel


Featured Flash FLA
Gallery Downloads 11401 Flash Movies | 5 New Flash Movies Added
What's New | Top 100

Featured FLA

»  Author Miguel Panos
»  Title: Tarta
»  Description: It is a circle graph or pie chart that takes the data entered by user
»  More by Miguel Panos


Random FLAs | Add Flash Movie
Featured Flash Site
Gallery Downloads 4839 Flash Sites | 1 New Flash Links
What's New | Top 100 Flash Site

Featured Site

»  AuthorDeft Creative Ltd
»  Link: Home Page
»  Description: Portfolio site for .DeftCreative Ltd. A UK based web design studio specialising in flash websites, games and interactive CDROMs. With an emphasis on making things different.


Random Links | Add your own Flash Related Links
Flash Tutorials 1484 Tutorials 7 New Tutorials Added!
What's New | Top100

» Making Automatic Training Screen Capture Easily
» Create Undersea Life Animation
» Making Deinterlace Video with a low bitrate Easily
» How To Make A Simple Animation Using Christmas Clips
» Simple Step by step flash game tutorial Spot the diffrence
» How To Make A Moving Text Slide
» Create Flash Banner With Text Float Effect
» How To Make Zoo Photos Slideshow
» How To Make A Dolphin Photos Slideshow
» Unknown Tag: Title10
Random Tutorial | Add Site


Tutorials Home What's New Top Rated Submit myTutes Random!

Search Tutorials


Tutorials Tutorials » Games

Categories Keeping track of dynamically drawn lines
Author: Jesse

 
Page 1
1 2 next»

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.

1 2 next»

» Level Intermediate

Added: : 2004-12-24
Rating: 7.71 Votes: 7
Hits: 245
» Author
Just started working with Flash.
» Download
Download the files used in this tutorial.
Download (3 kb)
Get conversion and unzipping tools for PC and Mac here!

» Forums
More help? Search our boards for quick answers!

Please rate this tutorial, 10 is the top rating, you can also click the comments link to read/write a review.
10 9 8 7 6 5 4 3 2 1
Read or Post Comments