[CENTER][COLOR=black][FONT=Verdana]API DRAWING[/FONT][/COLOR]
[/CENTER]
[COLOR=black][FONT=Arial]Yes I know I have not been here for quite some time, because of school. But I have some free time now… and I’m gonna write a tutorial.[/FONT][/COLOR]
I’m surprised at how many people don’t know what API is or they don’t know how to do it. For people who don’t know what API is, it’s a actionscript component built into Flash which you can use to draw anything with actionscript! Nothing in the frame and nothing in the library! Just pure actionscript!
So lets get started:
First you will have to create a brand new movieclip. There is only 1 line involved in doing this!
ActionScript Code:
[FONT=Courier New][LEFT]</p>
<p>[COLOR=#808080]//This will create an empty movieclip called box and with the depth of 1</p>[/COLOR]
<p>this.[COLOR=#0000ff]createEmptyMovieClip[/COLOR]COLOR=#000000[/COLOR]</p>
<p>
[/LEFT]
[/FONT]
Now you have to set the movieclips properties:
ActionScript Code:
[FONT=Courier New][LEFT]</p>
<p>[COLOR=#808080]//box.lineStyle(thickness,0xCOLORCODE)</p>[/COLOR]
<p>[COLOR=#808080]//You must have the 0x before you put the color code</p>[/COLOR]
<p>box.[COLOR=#0000ff]lineStyle[/COLOR]COLOR=#000000[/COLOR] [COLOR=#808080]//Sets the thickness to 1 and the line color to black</p>[/COLOR]
<p>[COLOR=#808080]//box.beginFill(0xCOLORCODE)</p>[/COLOR]
<p>box.[COLOR=#0000ff]beginFill[/COLOR]COLOR=#000000[/COLOR] [COLOR=#808080]//Sets the fill inside the box to yellow</p>[/COLOR]
<p>
[/LEFT]
[/FONT]
Now that we have set the properties we need to move the box somewhere to start drawing.
ActionScript Code:
[FONT=Courier New][LEFT]</p>
<p>[COLOR=#808080]//This will move the box so that you can start drawing (x,y)</p>[/COLOR]
<p>box.[COLOR=#0000ff]moveTo[/COLOR]COLOR=#000000[/COLOR] [COLOR=#808080]//Move it to 0 x and 0 y</p>[/COLOR]
<p>
[/LEFT]
[/FONT]
Now we can start drawing:
ActionScript Code:
[FONT=Courier New][LEFT]</p>
<p>[COLOR=#808080]//The line to method will draw a line from 0 x and 0 y (Which was set above) to the x and y you set it to move</p>[/COLOR]
<p>box.[COLOR=#0000ff]lineTo[/COLOR]COLOR=#000000[/COLOR] [COLOR=#808080]//Move from 0 x and 0 y to 0 x and 20 y</p>[/COLOR]
<p>box.[COLOR=#0000ff]lineTo[/COLOR]COLOR=#000000[/COLOR] [COLOR=#808080]//Move 20 x and stay at 20 y</p>[/COLOR]
<p>box.[COLOR=#0000ff]lineTo[/COLOR]COLOR=#000000[/COLOR] [COLOR=#808080]//Stay at 20 x and move up to 0 y</p>[/COLOR]
<p>box.[COLOR=#0000ff]lineTo[/COLOR]COLOR=#000000[/COLOR] [COLOR=#808080]//Go back to origanal spot</p>[/COLOR]
<p>
[/LEFT]
[/FONT]
Now we must move it to another location to view it better:
ActionScript Code:
[FONT=Courier New][LEFT]</p>
<p>[COLOR=#808080]//Moves the box to 100 x</p>[/COLOR]
<p>box.[COLOR=#0000ff]_x[/COLOR] = [COLOR=#000080]100[/COLOR]</p>
<p>[COLOR=#808080]//Moves the box to 200 y</p>[/COLOR]
<p>box.[COLOR=#0000ff]_y[/COLOR] = [COLOR=#000080]200[/COLOR]</p>
<p>
[/LEFT]
[/FONT]
Now test your movie… you will see that you have created a square!
Now you want things to happen when you click on the square, right!
ActionScript Code:
[FONT=Courier New][LEFT]</p>
<p>[COLOR=#808080]//When you press on the box a function is activated</p>[/COLOR]
<p>box.[COLOR=#0000ff]onPress[/COLOR] = [COLOR=#000000]function[/COLOR]COLOR=#000000[/COLOR] [COLOR=#000000]{[/COLOR]</p>
<p> [COLOR=#808080]//This will make the output box say “Wow you did it!”</p>[/COLOR]
<p> [COLOR=#0000ff]trace[/COLOR][COLOR=#000000]([/COLOR][COLOR=#ff0000]“Wow you did it!”[/COLOR][COLOR=#000000])[/COLOR]</p>
<p>[COLOR=#000000]}[/COLOR]</p>
<p>
[/LEFT]
[/FONT]
So your final code is:
ActionScript Code:
[FONT=Courier New][LEFT]</p>
<p>this.[COLOR=#0000ff]createEmptyMovieClip[/COLOR]COLOR=#000000[/COLOR]</p>
<p>[COLOR=#808080]//box.lineStyle(thickness,0xCOLORCODE)</p>[/COLOR]
<p>[COLOR=#808080]//You must have the 0x before you put the color code</p>[/COLOR]
<p>box.[COLOR=#0000ff]lineStyle[/COLOR]COLOR=#000000[/COLOR] [COLOR=#808080]//Sets the thickness to 1 and the line color to black</p>[/COLOR]
<p>[COLOR=#808080]//box.beginFill(0xCOLORCODE)</p>[/COLOR]
<p>box.[COLOR=#0000ff]beginFill[/COLOR]COLOR=#000000[/COLOR] [COLOR=#808080]//Sets the fill inside the box to yellow</p>[/COLOR]
<p>[COLOR=#808080]//This will move the box so that you can start drawing (x,y)</p>[/COLOR]
<p>box.[COLOR=#0000ff]moveTo[/COLOR]COLOR=#000000[/COLOR] [COLOR=#808080]//Move it to 0 x and 0 y</p>[/COLOR]
<p>[COLOR=#808080]//The line to method will draw a line from 0 x and 0 y (Which was set above) to the x and y you set it to move</p>[/COLOR]
<p>box.[COLOR=#0000ff]lineTo[/COLOR]COLOR=#000000[/COLOR] [COLOR=#808080]//Move from 0 x and 0 y to 0 x and 20 y</p>[/COLOR]
<p>box.[COLOR=#0000ff]lineTo[/COLOR]COLOR=#000000[/COLOR] [COLOR=#808080]//Move 20 x and stay at 20 y</p>[/COLOR]
<p>box.[COLOR=#0000ff]lineTo[/COLOR]COLOR=#000000[/COLOR] [COLOR=#808080]//Stay at 20 x and move up to 0 y</p>[/COLOR]
<p>box.[COLOR=#0000ff]lineTo[/COLOR]COLOR=#000000[/COLOR] [COLOR=#808080]//Go back to origanal spot</p>[/COLOR]
<p>[COLOR=#808080]//Moves the box to 100 x</p>[/COLOR]
<p>box.[COLOR=#0000ff]_x[/COLOR] = [COLOR=#000080]100[/COLOR]</p>
<p>[COLOR=#808080]//Moves the box to 100 y</p>[/COLOR]
<p>box.[COLOR=#0000ff]_y[/COLOR] = [COLOR=#000080]200[/COLOR]</p>
<p>[COLOR=#808080]//When you press on the box a fuction is activated</p>[/COLOR]
<p>box.[COLOR=#0000ff]onPress[/COLOR] = [COLOR=#000000]function[/COLOR]COLOR=#000000[/COLOR] [COLOR=#000000]{[/COLOR]</p>
<p> [COLOR=#808080]//This will make the output box say “Wow you did it!”</p>[/COLOR]
<p> [COLOR=#0000ff]trace[/COLOR][COLOR=#000000]([/COLOR][COLOR=#ff0000]“Wow you did it!”[/COLOR][COLOR=#000000])[/COLOR]</p>
<p>[COLOR=#000000]}[/COLOR]</p>
<p>
[/LEFT]
[/FONT]
You have made a box with a function, without the library and without drawing anything! Just pure actionscript!
Enjoy, Crayon-Inc.