Creating a simple doodle application using Actionscript 3.0

post1

Actionscript programming using Adobe Flash is very easy and interesting. Here we have a simple 15 mins  tutorial for creating a simple Doodle Application.

Step 1

  • Open up Adobe flash.
  • Create a new file (Flash File (Actionscript 3.0))
  • Press F9 so that you get the ‘actions’ window.
  • This is the place you are going to write code.

Step 2 (Intro to variables and event listeners)

Syntax

Variables : var <variable_name>:<variable_type> = <initial_value>;

Event Listener :  <object>.addeventListener(<event>,<callback_function>);

Function : function <function_name>(<Arguments>){

<Statements>

}

Example

The above example just demonstrates the usage of event listeners. A mouse down event listener is added to the stage object which triggers a function named ‘traceMe’. traceMe outputs the text “Hello World”.

Step 3(Creating Doodle)

In order to draw we need a ‘surface’. Here we create a new movie clip as our ‘surface’ and use its graphics properties to draw the line. ‘drawingLine’ is the new movie clip created and is inserted to the stage by using the function addChildAt 

addChildAt(<Child to insert>,<z-index>);

Algorithm

The mouse move event gives us a series of points when dragged. The aim is to draw lines connecting these points. We use the standard algorithm of storing the previous point in a variable so as to draw line connecting to the current point when the mouse is moved. The algorithm is described in detail below.

  1.  When MOUSE_DOWN(Click) event occurs store the point x,y to variables x1,y1 as discussed above. Also set isPressed to true to indicate that the user has initiated drawing.
  2. MOUSE_MOVE event is triggered every time the mouse is moved. So if ‘isPressed’ is true, draw line from the previous point stored to the current point. Also store the current point as the new previous point.
  3. MOUSE_UP is triggered when used leaves the mouse button. Here just set the ‘isPressed’ to false as the user has stopped drawing.

Code

 

 

 

2 thoughts on “Creating a simple doodle application using Actionscript 3.0

  1. Thanks for another informative site. The place else may I am getting that kind of information written in such a perfect manner? I have a undertaking that I’m just now running on, and I have been at the look out for such info.

  2. I do believe all of the ideas you have presented for your post. They are really convincing and will definitely work. Still, the posts are too brief for beginners. May just you please prolong them a bit from next time? Thanks for the post.

Leave a Reply