API is a way of drawing things using actionscript, it can be used draw simple things but it is difficult to go into much detail because of how it is done.
The codes are pretty basic, the main codes are:
createEmptyMovieClip("instance name", depth) - this makes an empty Movie Clip through actionscript and is needed to use API.
lineStyle(thickness, colour, alpha) - this is used to outline what properties your lines will have
lineTo(x, y) - this actually draws the line. Just input co-ordinates and a line will go from the current position to them.
curveTo(control X, control Y, anchor X, anchor Y) - this draws a curved line, its hard to use but can look good.
beginFill(colour, alpha) - this begins filling withing some lines which you specify using the lineTo command
endFill() - this ends the beginFill command
And then there are other commands such as:
moveTo(x, y) - this moves the current co-ordinate of the MC
with(instance name){ } - this is just used as a shortcut, inside the {'s, you place the lineTo commands and such.
---------
So, an example code. This will draw a simple square, place the code on the first frame of a new .fla file.
_root.createEmptyMovieClip("square", 1);
with(square){
//now we have made our square but it has nothing in it
lineStyle(2, 0x000000, 100);
//the line will be 2 pixels thick, black and 100% visible
beginFill(0x000000, 50);
//the fill will be black, and half visible
//now we will begin drawing
lineTo(50, 0);
lineTo(50,50);
lineTo(0, 50);
lineTo(0, 0);
}
If you test the flash now (ctrl+enter) you will see you have drawn a square using actionscript.
---------
Now, I'm going to do the same square, but using the 'curveTo' method.
_root.createEmptyMovieClip("square", 2);
with (curvedsquare) {
//now we have made our square but it has nothing in it
lineStyle(2, 0x000000, 100);
//the line will be 2 pixels thick, black and 100% visible
beginFill(0x000000, 50);
//the fill will be black, and half visible
//now we will begin drawing
curveTo(25, -10, 50, 0);
curveTo(60, 25, 50, 50);
curveTo(25, 60, 0, 50);
curveTo(-10, 25, 0, 0);
}
If you test that, it will make a square with sides that curve slightly, rather than just being straight.
-------
Ok, so far everything we've done is very simplistic. It would be much easier to do it within flash, and would take less time. The best thing about API is that you can change things dynamically, such as simulate the Windows mass select drag box.
Paste this into frame #1s actionscript panel:
onLoad = function () {
var1 = 0;
_root.createEmptyMovieClip("box", 1);
box.lineStyle(2, 0x0099FF, 100);
};
//when the flash loads, it will create a new variable called 'var1' that holds the number 0 and a new movieclip called 'box'
onMouseDown = function () {
box.moveTo(_xmouse, _ymouse);
var1 = 1;
curX = _xmouse;
curY = _ymouse;
};
//when the mouse is pressed, the box will move to the mouse point and the variables will all change
onMouseUp = function () {
var1 = 0;
};
//when the mouse stops being pressed, the var1 variable will equal 0
onEnterFrame = function () {
duplicateMovieClip("box", "box2", 2);
box2.lineStyle(2, 0x000000, 100);
//the box movieclip will be copied and the copy will be called 'box2'
if (var1 == 1) {
box2.beginFill(0x000000, 25);
box2.lineTo(_xmouse, curY);
box2.lineTo(_xmouse, _ymouse);
box2.lineTo(curX, _ymouse);
box2.lineTo(curX, curY);
}
//when the mouse is down, box2 will be drawn with the co-ordinates supplied.
};
The box will be drew from where the mouse is originally clicked, to where the mouse position is.
-------
You could also make a line from the mouse to a MC, with this:
onEnterFrame=function(){
createEmptyMovieClip("line", 10);
with(line){
lineStyle(2, 0x000000, 100);
moveTo(_xmouse, _ymouse);
lineTo(instance name of MC1._x, instance name of MC1._y);
}
}
------
For more advanced coders (read: people with more time on their hands), you could make an entire game out of actionscript.
1. Set your variables. We need the following variables:
score = 0;
time = 0;
rand1 = random(250)+25;
2. Create your character, I won't go into much detail.. instead I'll use a basic square:
_root.createEmptyMovieClip("char1", 50);
with (char1) {
lineStyle(2, 0xFFFFFF, 100);
moveTo(_x-15, _y-15);
beginFill(0xFFFFFF, 50);
lineTo(_x+15, _y-15);
lineTo(_x+15, _y+15);
lineTo(_x-15, _y+15);
lineTo(_x-15, _y-15);
endFill();
}
3. Now underneath, make three movieclips which will make up the floor and one for the floor colour:
_root.createEmptyMovieClip("wall1", 10);
with (wall1) {
lineStyle(5, 0x000000, 100);
moveTo(0, 200);
lineTo(rand1, 200);
}
_root.createEmptyMovieClip("wall2", 11);
with (wall2) {
lineStyle(5, 0x000000, 100);
moveTo(rand1, 250);
lineTo(550, 250);
}
_root.createEmptyMovieClip("wall3", 12);
with (wall3) {
lineStyle(5, 0x000000, 100);
moveTo(rand1, 200);
lineTo(rand1, 250);
}
_root.createEmptyMovieClip("base", 0);
with (base) {
lineStyle(1, 0x000000, 0);
moveTo(0, 200);
beginFill(0x00CC66, 100);
lineTo(rand1, 200);
lineTo(rand1, 250);
lineTo(550, 250);
lineTo(550, 400);
lineTo(0, 400);
lineTo(0, 200);
endFill();
}
4. Make a coin, this is just a square, basic coin but still, it is something to collect.
_root.createEmptyMovieClip("coin1", 100);
with (coin1) {
lineStyle(2, 0xFFFF00, 100);
beginFill(0xFFCC00, 100);
lineTo(_x+10, _y);
lineTo(_x+10, _y+10);
lineTo(_x, _y+10);
lineTo(_x, _y);
endFill();
_x = random(400)+50;
_y = random(180);
}
***TO BE CONTINUED IN NEXT POST***
Sup, bitches :)