This is my first tutorial i worked really hard on it and it took about 3 hours i tried to make it like Pols and explain everything and i hope i did a good job.
After reading this tutorial u should have enough knowledge to make your own simple game in flash. First thing u need to know how to do is make movieclips. To make a movieclip u must make the object u want to be a movieclip then take the mouse and click over the object and with it highlighted press f8 which should bring up another window click on movieclip and give it a name (note this is not the instance name which ill be referring to later)then click ok and the object should be surrounded in a blue square which means its selected. Now to add the script, with the object selected click the actions tab.
NOTE: ALL ACTIONSCRIPT IS IN BLUE
Event Handlers:
First thing i'm gonna talk about is movie clip event handlers. Event handlers start the script. onClipEvent(enterFrame) and onClipEvent(load) are the two event handlers. U use onClipEvent(enterFrame) when u want the actionscript to work everytime u enter a certain frame in the movie. onClipEvent(load) is used when u want the actionscript to happen only when the movie or game loads. Next thing im gonna talk about is button event handlers. A button event handler is event handlers u use to start off the actionscript of a button. Heres all the button event handlers: on(press) and on(release).
Operators:
Operators are signs such as + and = here is a list of operators:
+ means addition, - means subtraction, * means multiplication, / means division, % means Modulo(remainder of division), ++ means Increment, -- means Decrement, = means Equals(numeric operator used to assign variables, properties, methods, etc.), == means is equal to(comparison operator used to compare values), === means Is equal to (comparison operator used to compare non-string values and their data types), != means Is not equal to(comparison operator used to compare values), < means Less than (comparison operator used to compare values), > means Greater than (comparison operator used to compare values), <= means Less than or equal to (comparison operator used to compare values), >= means Greater than or equal to (comparison operator used to compare values), && means AND (logical operator that returns TRUE if both operands are true), || means OR (logical operator that returns TRUE if the left or right operand is true), ! means NOT (logical operator that returns the Boolean opposite of the operand following the ! operator.
Commenting your code:
Commenting your code is used very often to remind yourself what your code does. To comment your code u type // and everything after that is comments and doesnt affect the code.
Variables:
In this code
onClipEvent(enterFrame){
moveSpeed = 10;
}
moveSpeed would be the variable.
Making a button:
Theres many ways to make a button first u must make the object u want to be pressed then when u press f8 instead of clicking movieclip click button and in the actions tab u must first start with a button event handler either on(press){ or on(release){ then in the next line u must put what action u want to happen when the button is pressed. So if u wanted to go to frame 5 when the button is released u would put
on(release){
gotoAndPlay(5);
}
when u make a button such as a play button where u dont want anything to happen until the button is pressed in the timeline u must click the frame the button is on and then open up the actions tab and put this code stop(); which stops the animation until a button is pressed to make it play again
Instance Names:
Instance names are what u use in actionscript to set the instance name u must first make the object then press f8 and make it a movieclip then in the properties tab there is a box that says instance name in there type what u want the instance name to be
Putting it all together:
Heres the basic moving script
onClipEvent(load){
moveSpeed = 5;
}
This piece of script tells the program to set the variable moveSpeed at 5
onClipEvent(enterFrame){
if(Key.isDown(Key.UP)){
this._y -= moveSpeed;
}
In this script onClipEvent(enterFrame){ is the event handler, if(Key.isDown(Key.UP)){ tells the program to perform the action in the next line when the up key is pressed, and -= is the operator which means if the down key is pressed subtract the speed by moveSpeed which would make the object stop
This is the scripts for down, right, and left
if(Key.isDown(Key.DOWN)){
this._y += moveSpeed;
}
if(Key.isDown(Key.RIGHT)){
this._x += moveSpeed;
}
if(Key.isDown(Key.LEFT)){
this._x -= moveSpeed;
}
}
Hittest:
Hittest is a script that does something when one object hits another object. Hittest always starts with onClipEvent(enterFrame){, and the second line goes like this if(this.hitTest(_root.instance name of object u want to show is being hit)){ then the third line shows what action u want to happen when one object hits another object. If u want to go to frame 7 when an object with instance name "player" hits an object with an instance name "enemy" the code would look like this.
onClipEvent(enterFrame){
if(this.hitTest(_root.enemy)){
gotoAndPlay(7);
}
}
when u want to make a wall type effect u must use this code (the wall has an instance name of wall)
right wall
onClipEvent(enterFrame){
if(this.hitTest(_root.wall)){
this._x -= moveSpeed;
}
}
left wall
onClipEvent(enterFrame){
if(this.hitTest(_root.wall)){
this._x += moveSpeed;
}
}
top wall
onClipEvent(enterFrame){
if(this.hitTest(_root.wall)){
this._y -= moveSpeed;
}
}
bottom wall
onClipEvent(enterFrame){
if(this.hitTest(_root.wall)){
this._y += moveSpeed;
}
}
Extra Scripts:
to make a movieclip with the instance name "enemy" move towards a movieclip with an instance name "player" at a speed of 5 the code would be
onClipEvent(load) {
speedX = 5;
speedY = 5;
}
onClipEvent(enterFrame) {
if(_root.player._x > this._x) {
this._x += speedX;
}
if(_root.player._x < this._x) {
this._x -= speedX;
} else if((_root.player._x - this._x) <= 2 && (_root.player._x - this._x) >= -2) {
randFrame = 2 + Math.floor(Math.random()*(2-1+1));
this.gotoAndPlay(randFrame);
}
if(_root.player._y > this._y) {
this._y += speedY;
}
if(_root.player._y < this._y) {
this._y -= speedY;
} else if((_root.player._y - this._y) <= 2 && (_root.player._y - this._y) >= -2) {
randFrame = 2 + Math.floor(Math.random()*(2-1+1));
this.gotoAndPlay(randFrame);
}
}
I used this script in my portal game.
Random Movement
onClipEvent (load) {
time=0;
dir=2;
speed=20;
}
onClipEvent (enterFrame) {
maxTime = random(5);
time++;
if (time>=maxTime) {
time = 0;
}
if (time == 0) {
dir = random(20);
}
if (dir == 0) {
this._y -= speed;
} else if (dir == 1) {
this._y += speed;
} else if (dir == 2) {
this._x -= speed;
} else if (dir == 3) {
this._x += speed;
}
}
Jumping Script
onClipEvent (load) {
grav_y = 0;
jumping = false;
}
onClipEvent (enterFrame) {
if (Key.isDown(Key.SPACE) && !jumping) {
grav_y = 20;
jumping = true;
}
if (jumping == true) {
grav_y -= 1;
if (grav_y<=-10) {
grav_y = -10;
}
this._y -= grav_y;
}
if (_root.ground.hitTest(this._x, this._y+45, true)) {
grav_y = 0;
jumping = false;
}
}
NOTE: if you want to have the character to stop at a ground point, you must make a movieclip and label it ground
I hope this tutorial helped if it did dont be afraid to push the rep button
Actionscript Tutorial [Flash][Actionscript]
Started by: sactownboy10 | Replies: 14 | Views: 7,298
sactownboy10
Posts: 0
Joined: Aug 2025
Posts: 0
Joined: Aug 2025
Sep 4, 2005 1:31 AM #412
fedo
Posts: 0
Joined: Aug 2025
Posts: 0
Joined: Aug 2025
Sep 4, 2005 1:38 AM #414
wow that desirves a rep but ive given out to much random rep today so w8 a little.
schtick
Posts: 0
Joined: Aug 2025
Posts: 0
Joined: Aug 2025
Sep 4, 2005 1:39 AM #415
very helpful, *marks as favorite*, +rep....i wonder if it did anything?
Noob Style
Posts: 0
Joined: Aug 2025
Posts: 0
Joined: Aug 2025
Sep 4, 2005 11:51 AM #421
nice tut imma gonna reppa you a todaya woota! try my new exciting fun adventure game too! http://img371.imageshack.us/my.php?image=cool4bk.swf
Sep 4, 2005 12:12 PM #422
Give a man a fish he lives for a day.
You didnt explain many of the scripts.
You didnt explain many of the scripts.
briceman92
Posts: 0
Joined: Aug 2025
Posts: 0
Joined: Aug 2025
Nov 13, 2005 2:00 AM #2025
I liked the enemy one:
Click the middle of it to focus the computer on it.
Arrow keys to move the Red Ball
Blue Ball follows the Red Ball
Green Ball follows the Blue Ball
[SWF="http://i4.photobucket.com/albums/y109/briceman92/ballsfollow.swf height=300 width=400"]http://i4.photobucket.com/albums/y109/briceman92/ballsfollow.swf[/SWF]
Thanks Again! :D
Click the middle of it to focus the computer on it.
Arrow keys to move the Red Ball
Blue Ball follows the Red Ball
Green Ball follows the Blue Ball
[SWF="http://i4.photobucket.com/albums/y109/briceman92/ballsfollow.swf height=300 width=400"]http://i4.photobucket.com/albums/y109/briceman92/ballsfollow.swf[/SWF]
Thanks Again! :D
Fig Newton
Posts: 0
Joined: Aug 2025
Posts: 0
Joined: Aug 2025
Dec 26, 2005 1:29 AM #3023
nice ass tut, i mean as tut. lol
Mike Rotch
Posts: 0
Joined: Aug 2025
Posts: 0
Joined: Aug 2025
Feb 7, 2006 11:38 PM #4576
confusing but g00d i likey
Mar 30, 2006 3:00 AM #6765
the jump one dose not work, i did make a movie clip and named it ground but it still didnt work
Apr 17, 2006 5:09 PM #8021
Quote from Noob Stylenice tut imma gonna reppa you a todaya woota! try my new exciting fun adventure game too! http://img371.imageshack.us/my.php?image=cool4bk.swf
Oh! Please can you give me the scripts to make this paint thing?
Apr 17, 2006 5:35 PM #8022
http://stickpage.com/vb/showthread.php?t=24110&highlight=drawing i made that ages ago.
Luigil0wz
Posts: 0
Joined: Aug 2025
Posts: 0
Joined: Aug 2025
Aug 18, 2008 10:50 PM #226449
please som1 help me im a noobie there i said it
sactownboy10
Posts: 0
Joined: Aug 2025
Posts: 0
Joined: Aug 2025
Nov 16, 2008 3:58 AM #295376
Im glad my tutorial could help you guys
mysterybox
Posts: 0
Joined: Aug 2025
Posts: 0
Joined: Aug 2025
Nov 20, 2008 5:56 AM #298121
Nice, Helped alot.
Sep 26, 2009 2:11 PM #492229
*favorite it* Really great, and helpfull soon i will have my game ^^