Tutorial (API DRAWING)

[CENTER][CENTER][COLOR=black][FONT=Verdana]API DRAWING[/FONT][/COLOR][COLOR=black][FONT=Arial][/FONT][/COLOR][/CENTER]
[CENTER][COLOR=black][FONT=Arial] [/FONT][/COLOR][/CENTER][/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!


//This will create an empty movieclip called box and with the depth of 1
this.createEmptyMovieClip("box",1)

Now you have to set the movieclips properties:


//box.lineStyle(thickness,0xCOLORCODE)
//You must have the 0x before you put the color code
box.lineStyle(1,0x000000) //Sets the thickness to 1 and the line color to black
//box.beginFill(0xCOLORCODE)
box.beginFill(0xFFFF00) //Sets the fill inside the box to yellow

Now that we have set the properties we need to move the box somewhere to start drawing.


//This will move the box so that you can start drawing (x,y)
box.moveTo(0,0) //Move it to 0 x and 0 y

Now we can start drawing:


//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
box.lineTo(0,20) //Move from 0 x and 0 y to 0 x and 20 y
box.lineTo(20,20) //Move 20 x and stay at 20 y
box.lineTo(20,0) //Stay at 20 x and move up to 0 y
box.lineTo(0,0) //Go back to origanal spot

Now we must move it to another location to view it better:


//Moves the box to 100 x
box._x = 100
//Moves the box to 200 y
box._y = 200

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!


//When you press on the box a function is activated
box.onPress = function() {
          //This will make the output box say "Wow you did it!"
          trace("Wow you did it!")
}

So your final code is:


this.createEmptyMovieClip("box",1)
//box.lineStyle(thickness,0xCOLORCODE)
//You must have the 0x before you put the color code
box.lineStyle(1,0x000000) //Sets the thickness to 1 and the line color to black
//box.beginFill(0xCOLORCODE)
box.beginFill(0xFFFF00) //Sets the fill inside the box to yellow
//This will move the box so that you can start drawing (x,y)
box.moveTo(0,0) //Move it to 0 x and 0 y
//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
box.lineTo(0,20) //Move from 0 x and 0 y to 0 x and 20 y
box.lineTo(20,20) //Move 20 x and stay at 20 y
box.lineTo(20,0) //Stay at 20 x and move up to 0 y
box.lineTo(0,0) //Go back to origanal spot
//Moves the box to 100 x
box._x = 100
//Moves the box to 100 y
box._y = 200
//When you press on the box a fuction is activated
box.onPress = function() {
          //This will make the output box say "Wow you did it!"
          trace("Wow you did it!")
}

You have made a box with a function, without the library and without drawing anything! Just pure actionscript!

Enjoy, Crayon-Inc.
[COLOR=black][FONT=Arial] [/FONT][/COLOR]