Hello! This is a tutorial that has the previous, deleted tutorials info in it too, and some more. I’m going to show how to make a simple jetpack man application engine. So, now Ill start ![]()
ActionScript 2!
First off, draw a jetpack man or anything that you’re going to control. Select it and press f8. A window pops up. Name it whatever you want, and remember to put the registration point into the center of the movieclip. Make the instance name of it to “fly” without quotes. Now you got everything there done. Now, click on the main timeline, which looks like a thin box that has a circle in it. Press f9 to bring up the actionscript-panel. Now type in the following code in it:
1 2 3 4 5 6 7 8 9 10 11 12 13 14 15 16 17 18 19 20 21 22 23 24 25 26 27 28 29 30 31 32 33 | yspeed = 0; xspeed = 0; gravity = 0.2; rotationspeed = 0; power = 1; friction = 0.9; fly.onEnterFrame = function() { yspeed += gravity; xspeed *= friction; this._x += xspeed; rotationspeed *= friction; this._rotation = 0+rotationspeed; if (this._y<=400-this._height/2) { this._y += yspeed; if (Key.isDown(37)) { xspeed -= power; rotationspeed += power*xspeed/2; } else if (Key.isDown(39)) { xspeed += power; rotationspeed += power*xspeed/2; } } else { xspeed *= friction; yspeed = 0; this._y = 400-this._height/2; } if (Key.isDown(38)) { yspeed -= power; } if (yspeed<0) { yspeed *= friction; } }; |
When you’ve done that, press ctrl+enter to see how it looks like. If you followed these easy steps right, the result should look a bit like this:
![]()
Now to the explanation:
Rows 1 - 6 are just the variables that makes it possible to make everything run. You could try to change the value of gravity, power and friction to see what happens. The three others are just variables that control the movement of the character.
Row 7 adds an function that runs every frame and does the actions that are written into it.
Rows 8 - 12 adds things to the variables and are then added to the jetpack characters _x, _y and _rotation values, that then makes it controlable.
Row 13 checks if the jetpack man is not touching the “ground”. In next tutorial I will show how to make platforms for it.
Rows 14 - 20. The first thing thats on row 14 makes so it can fly vertically.
Then it checks if a key is pressed, which in this case are key 37 on row 15, and key 39 on row 18. So, what are the numbers? They are the keycodes for the keys. All keys on the keyboard has one. This picture will show you the keys that are usually used in games:

The keys that is watched if theyre pressed is the left and right arrow key. They make the jetpack square go to left and right. And that means that it changes the rotationspeed and xspeed variables.
Rows 23 - 25 is what happens when the jetpack square hits the “ground”. xspeed var is decreased, _y is set to the right place and yspeed is set to 0.
Rows 27 - 29 is the thrust button action. The keycode thats 38 is for the up arrowkey. And if thats pressed, the character flies up.
Rows 30 - 32 looks if its flying upwards, and if it is, yspeed is decreased some extra. Else it would fly to mars in 3 seconds.
Thats all! If you couldnt get it to work, download the source from here.
If you liked this tutorial, you could play my, *cough* really good games here.














April 9th, 2008 at 13:59:44
Very nice!
I like it.
April 11th, 2008 at 18:15:46
Great. Loved it thanks! Very helpful 4 stars!
April 22nd, 2008 at 19:36:07
[...] *COUGH* [...]
May 4th, 2008 at 15:23:25
i followed every step in the bottom
First off, draw a jetpack man or anything that you’re going to control. Select it and press f8. A window pops up. Name it whatever you want, and remember to put the registration point into the center of the movieclip. Make the instance name of it to “Fly” without quotes. Now you got everything there done. Now, click on the main timeline, which looks like a thin box that has a circle in it. Press f9 to bring up the actionscript-panel. Now type in the following code in it:
[Copy to clipboard][-]
View CodeACTIONSCRIPT
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
yspeed = 0;
xspeed = 0;
gravity = 0.2;
rotationspeed = 0;
power = 1;
friction = 0.9;
fly.onEnterFrame = function() {
yspeed += gravity;
xspeed *= friction;
this._x += xspeed;
rotationspeed *= friction;
this._rotation = 0+rotationspeed;
if (this._y<=400-this._height/2) {
this._y += yspeed;
if (Key.isDown(37)) {
xspeed -= power;
rotationspeed += power*xspeed/2;
} else if (Key.isDown(39)) {
xspeed += power;
rotationspeed += power*xspeed/2;
}
} else {
xspeed *= friction;
yspeed = 0;
this._y = 400-this._height/2;
}
if (Key.isDown(38)) {
yspeed -= power;
}
if (yspeed<0) {
yspeed *= friction;
}
};
When you’ve done that, press ctrl+enter to see how it looks like. If you followed these easy steps right, the result should look a bit like this:
but it still does not work
May 4th, 2008 at 17:38:52
you fuker it dosent work evrey tut i go to it never works WHY
May 4th, 2008 at 18:42:52
add the actionscript code to the same frame as the jetpack or whatever you are wanting to move.
May 5th, 2008 at 10:11:13
it doesn’t work
May 5th, 2008 at 14:14:29
“Make the instance name of it to “Fly”
correction : it’s “fly”, not “Fly”
May 5th, 2008 at 18:29:44
AAAAAAAAAAAAAAHHHHHHHHHHHHHHHHH!!!!!!!!!!!!!!!!!!!!!!!!!!!
WHY DO YOU POST THINGS THAT DON’T WORK!?
TEST YOUR STUFF BEFORE YOU PUT IT ON THE WEB!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!
May 6th, 2008 at 11:40:55
It works just you are a noob and you can’t programming
May 6th, 2008 at 15:27:23
of course its not going to work if you capitalized the F in fly. If you dont capitalize it…IT WILL WORK!
May 6th, 2008 at 15:31:10
and u can also change the speed by changing the frame rate on the properties bar.
May 7th, 2008 at 10:20:30
What is this instances he talks abou…name the instances to Fly? wtf is he on about!
May 7th, 2008 at 21:59:22
on the code do u have to put the numbers which is in front of the code?
May 8th, 2008 at 03:24:03
If ur thinking sumthin like this:
“What is this instances he talks abou…name the instances to Fly? wtf is he on about!”
then you shouldnt be trying to do this tutorial…..or anything in action script…..except: stop(); but thats about the only thing u can use without making anything an instance.
May 8th, 2008 at 04:32:53
Very nice, works like a charm even on older versions. On older versions *where function keys serve no purpose* when he refers to “F8″ he means the properties window, where not only the instance needs to be called “fly” but the specific one you place on the scene needs to have its name put to “fly” (took me a min to realise that)
May 8th, 2008 at 16:52:27
Lol Moff u r such a fag. . .can u not type?????? Newb
May 8th, 2008 at 20:24:14
Amazing tutorial mate, thanks a billion
and to all those fags that says it don’t work… SHUT THE HELL UP!!!!
best of luck in the future
Stupid Saint
May 9th, 2008 at 08:10:27
Nope at first i thought this is another not working tutorial that i have come across but i downloaded the source file and realised that i didnt set the instance name to fly, simple mistake of reading it, if it didnt work for you before ytou post read this, the instance name needs to be called “fly” no quotes and the actionscript needs to be in the frame itself, the tut does work
May 11th, 2008 at 08:52:27
Im new at this, whats an “instance name” u were refering to? if its the “Name” why make it confusing?
May 11th, 2008 at 20:51:53
If you dont understand how it should be, just download the source from here and see how it works
May 12th, 2008 at 00:53:34
nvm, the instance name is on the “properties” when F9 bring it up. You know, people that asks stupid questions only means that they are starting to learn this
May 12th, 2008 at 00:54:22
I learned where the instance name was located through another website btw..
May 12th, 2008 at 04:41:23
not through this source, a lot of source I had downloaded doesnt open with the program I use, so…
May 14th, 2008 at 07:45:00
hey um what does it mean by instance name fly, wtf is a instance name i don’t get it.
May 14th, 2008 at 07:47:53
where do i find the instance name the source didn’t help me at all
May 14th, 2008 at 07:53:06
never mind i figured it, out you have to click your drawing and go to properties right under the action script bar then bam instance name and it does work !!
May 14th, 2008 at 20:44:39
Wow man this worked, and it was easy. Thanks a whole lot. At first it wasnt working because I was using actionscript 3 (hint hint) but i switched to 2, and it works! =)
May 15th, 2008 at 00:10:10
hey tom it doesnt work cuz u suck at programing
May 15th, 2008 at 01:57:05
great tutorial…
is there a way to make it move side to side instead of rotating when LEFT/RIGHT are pressed?…
May 18th, 2008 at 21:24:07
how do i change the instance name?
May 19th, 2008 at 21:58:37
You can see how to change the instance name in part 2 of these tutorials
May 19th, 2008 at 22:01:39
[...] Jetpack game - part 1 [...]
May 21st, 2008 at 07:11:59
Thanks …. awesome tutorial just what i was looking for. Easy to follow
May 24th, 2008 at 18:34:06
Excelent!!!!!!!!!!!!!!!!!1
May 26th, 2008 at 18:27:48
Thanks a lot!
It works. I didn’t name the instance properly… but then I clicked my “jetpack” and looked at its properties. I noticed, that the instance name is empty.
May 27th, 2008 at 13:26:49
I figured out the problem for everyone here…..
WHEN CONVERTING INTO A MOVIE CLIP…….
It gives you the option of converting into a movie clip, button, and graphics, and of course you would press movie clip in this situation but….
A little to the right of those options is a thingy that says “registration” and to the right it shows 9 little circles (the upper left one is already darkened)
MAKE SURE YOU PRESS THE CENTER DOT BEFORE MAKING IT A MOVIE CLIP!!
Haha it took me like 15 minutes to figure out what the hell a registration point was (like said above in the tutorial) but I found once i centered the registration point while making it a movie clip, made the whole different and now I have a little jetpack man game
May 27th, 2008 at 22:40:33
Worked for me Thank u
June 1st, 2008 at 19:45:18
i am new aswell but i figured out the instance name out by my self very quickly so just have a look for it if you dont understand where it is and it does work. great tutorial
June 2nd, 2008 at 09:52:11
For all stupid man who post such thing that blah blah blah…the action script doesn’t work.
First follow all the steps, it works!!! Only you are such foulish man.
Thanks for the man who posted this tutorial.
June 2nd, 2008 at 10:56:29
Just what i was looking for, And the code dose work and is very flexible to change. Thanks for posting it..
June 3rd, 2008 at 16:21:22
its gr8 it works for me….. I think som1s copied even the numbers wich is in the left… nyway its gr8, thnx for posting
June 4th, 2008 at 15:49:58
Hey, to all those who can’t make it work. When you click on the object, look in the properties menu and ensure the space in the top left corner, under , that says says . It will work.
OOrah.
June 7th, 2008 at 05:56:05
great job works perfectly to my needs =)
June 12th, 2008 at 18:50:53
this script is better
-no instance name needed
-goes in the in the movie clip
-as 1.0 as well as 2.0
-more simple
onClipEvent (load) {
yspeed = 0;
xspeed = 0;
gravity = 0.2;
rotationspeed = 0;
power = 1.1;
friction = 0.9;
}
onClipEvent (enterFrame) {
if (this._y<=400-this._height/2) {
this._y += yspeed;
if (Key.isDown(Key.LEFT)) {
xspeed -= power;
rotationspeed += power*xspeed/2;
} else if (Key.isDown(Key.RIGHT)) {
xspeed += power;
rotationspeed += power*xspeed/2;
}
} else {
xspeed *= friction;
yspeed = 0;
this._y = 400-this._height/2;
}
if (Key.isDown(Key.UP)) {
yspeed -= power;
}
if (yspeed<0) {
yspeed *= friction;
}
yspeed += gravity;
xspeed *= friction;
this._x += xspeed;
rotationspeed *= friction;
this._rotation = 0+rotationspeed;
}
June 15th, 2008 at 06:20:31
thank ypu Oran, since the guy who posted this tuturial did not work
June 18th, 2008 at 07:21:19
i use the first code but get these errors!
**Error** Scene=Scene 1, layer=Layer 1, frame=1:Line 7: Operator ‘=’ must be followed by an operand
fly.onEnterFrame = function() {
**Error** Scene=Scene 1, layer=Layer 1, frame=1:Line 1: Statement must appear within on/onClipEvent handler
yspeed = 5;
**Error** Scene=Scene 1, layer=Layer 1, frame=1:Line 2: Statement must appear within on/onClipEvent handler
xspeed = 5;
**Error** Scene=Scene 1, layer=Layer 1, frame=1:Line 3: Statement must appear within on/onClipEvent handler
gravity = 0.2;
**Error** Scene=Scene 1, layer=Layer 1, frame=1:Line 4: Statement must appear within on/onClipEvent handler
rotationspeed = 0.5;
**Error** Scene=Scene 1, layer=Layer 1, frame=1:Line 5: Statement must appear within on/onClipEvent handler
power = 1;
**Error** Scene=Scene 1, layer=Layer 1, frame=1:Line 6: Statement must appear within on/onClipEvent handler
friction = 0.9;
**Error** Scene=Scene 1, layer=Layer 1, frame=1:Line 7: Statement must appear within on/onClipEvent handler
fly.onEnterFrame = function() {
What does it mean???
June 23rd, 2008 at 09:12:27
You need Adobe Flash 8 Professional to do it! At least i did it and it worked for me:D
July 1st, 2008 at 05:11:10
First of all:
No one here should be complaining about any of Aksel’s code unless they have actually learned the basics of Actionscript. ‘instance’ is just fancy talk for ‘object’
2nd:
“fly.onEnterFrame = function {}” does not work in ActionScript 2.0. this only works in ActionSCript 1.0. For those of you that say it doesnt work, this is the reason. Flash 8, by default, uses Actionscript 2.0 unless you change it.
instead of calling a onClipEvent thru a new function. you can call it itself. :
onClipEvent(enterFrame){}
I hope this clears up all the commotion. Best of luck to all; Beginners and Advanced!
July 1st, 2008 at 05:18:37
Also. If you are using Flash CS3. Change your ActionScript library that you are using to AS 2.0. Make sure the check it is changed during your documents export/publish stage. If you dont know how to do this. Read the Adobe Flash Live Docs. Everything isn’t going to be spoon fed. You find the Live Doc by clicking Help in the Menu at top of screen.
July 1st, 2008 at 05:21:26
and Very nice tutorial Aksel. May not work for some but, it is very well explained. Use comments (a suggestion). Might make it simpiler.
July 26th, 2008 at 00:30:43
onClipEvent (load) {
yspeed = 0;
xspeed = 0;
gravity = 0.2;
rotationspeed = 0;
power = 1.1;
friction = 0.9;
}
onClipEvent (enterFrame) {
if (this._y<=400-this._height/2) {
this._y += yspeed;
if (Key.isDown(Key.LEFT)) {
xspeed -= power;
rotationspeed += power*xspeed/2;
} else if (Key.isDown(Key.RIGHT)) {
xspeed += power;
rotationspeed += power*xspeed/2;
}
} else {
xspeed *= friction;
yspeed = 0;
this._y = 400-this._height/2;
}
if (Key.isDown(Key.UP)) {
yspeed -= power;
}
if (yspeed<0) {
yspeed *= friction;
}
yspeed += gravity;
xspeed *= friction;
this._x += xspeed;
rotationspeed *= friction;
this._rotation = 0+rotationspeed;
}
this code found!
August 4th, 2008 at 19:21:30
Great tut. I am still trying to figure part 2 though.
November 2nd, 2008 at 16:33:54
[...] Jetpack game - Part 3 [...]
November 5th, 2008 at 04:46:47
great works fine,
thanx
November 23rd, 2008 at 23:58:16
i’m kind of a noob at this ation script stuff and i have the trail for cs4 it uses ation script 3.0 but it will let u use 2.0 it tells me the first 7 lines have errors and they say “satement must appear within on/onClipEvent handler” thats what it says for the first seven lines and how do you name an instance ty
November 24th, 2008 at 00:09:34
wait i did’t type it right i got it
December 8th, 2008 at 23:02:31
I have the instance name as fly and I have the registration point in the middle. I copied the script into the action script box and it is set to movie clip and i hit ctrl and enter but it still doesnt work. Any help?
January 7th, 2009 at 09:11:48
i like this tutorial..can some one post..how we can impliment collision and other physics in flash…
January 29th, 2009 at 13:50:26
for the idiots which can’t make this code work
im 12 years old, and i figured out my first day rpgramming at flash this:
“the ones which can’t think, can’t program”
so, you shall all go to another website and learn it there, becuase, if you didn’t undestand this tut, is because you have a serious mind problem. maybe ‘down’.
or you could just try follow the tutoril again and paste dthe code on the ‘main timeine’ as he says. or put the instance of ‘lfly’ as he also says or download the source as he says!
January 30th, 2009 at 16:53:15
It doesnt work at me to but i think for the people where it doesnt works we maybe have a other flas player;) i got so many messages that its wrong on my flash thati think i have an other version;)
February 1st, 2009 at 20:47:11
Try pasting the script in the first keyframe
March 20th, 2009 at 12:13:58
great tutorial worked on the old flash on the pc`s at school but didnt work on the new version i have at home
October 25th, 2009 at 12:48:44
Hey guys!
Be sure to put the code in the KEYFRAME - not the object
I made that misstake at first
Or if you follow David’s Code - That one is applied to the object
have fun