Monday, February 16, 2009

How to create API drawing in flash

API Drawing

Flash MX comes with a wide range of new features. On of these new features if the "API Drawing" ability. This means you can start off with a completly blank stage and have your script do the drawing at runtime. In this tutorial I will teach you how to make the above drawing application using API. I expect you to be able to use and have a strong knowledge in actionscripting.

Tutorial

1) create a new movie and select the first frame. Open the actionscript window so your ready to enter code. first you will enter the code to create a movie clip.

createEmptyMovieClip("myClip",1);

2) Now you will set the thickness, colour, and alpha value of the line. The colour is a hexadecimal value, and the alpha is a value between 1 and 100.

myClip.lineStyle(1,0x000000,100);

3) This following code will actualy draw the line when you put you click your mouse button.

onMouseDown = function () {
myClip.moveTo(_xmouse, _ymouse);
onMouseMove = function () { myClip.lineTo(_xmouse, _ymouse);};
};
onMouseUp=function(){
onMouseMove=null;
}

The function "onMouseDown" activates when you click your mouse button. it then moves the mouse to the starting point of your line, which will be directly under where you clicked. "onMouseMove" draws a line to your mouse using the lineTo() action. "onMouseMove" is used as aposed to "onEnterFrame" because it is only active when the user is moving there mouse. The last function "turns off" the "onMouseMove" function so that the line will not be drawn agian until the user clicks the mouse button agian.

All this code is to be entered into the first frame of your movie clip in the sequence that is displayed here.

source : www.bezzanet.zzn.com

2 comments:

Anonymous | March 4, 2009 at 8:14 AM  

good post, I'm looking for this for a week, thanks lazacode;)

Anonymous | March 4, 2009 at 8:15 AM  

How about something similar with as 3.0? Any idea how the code should look like? can you post it here?

Post a Comment