This is an archived tutorial from the kirupa.com legacy collection. It covers software that may no longer be available, but it is kept online because the ideas still hold up.
Something that Flash is really good for is games. While Macromedia's Director is used for the complex web-based games, Flash has the capabilities to help you create great games. If you do not believe me, play some excellent Flash games on Ferry Halim's site Orsinal: http://www.ferryhalim.com/orisinal/
Needless to say, I do not have the intricate knowledge of programming (yet) to create great games as Mr. Halim. But I do know how to create some simple games and the basics behind creating them. Here is an example of the Guess the Numbers game:
This tutorial will help you to create a simple "guess the numbers" game. More specifically, the tutorial will be broken down into the following parts:
The best way to start exploring movement is to take a simple object and move it horizontally along the x axis. The following is an example of an object that moves along the x axis powered by only a few lines of code:
[ press the 'start over' text if you do not see anything ]
Let's create the above animation:
onClipEvent(enterFrame) {
speed = 1;
this._x += speed;
}
[ copy and paste the above code into the Actions dialog box ]
Not to leave you in the dark, I will explain what each line of the code accomplishes.
onClipEvent(enterFrame)
{
speed = 1;
this._x
+= speed;
}
The first line is nothing more than the
OnClipEvent event handler (enterFrame)
that executes the code continuously in a one frame movie
clip.
In the second line, I am declaring and
initializing the variable speed
with a value of 1. As is
expected, the variable speed refers to the speed at which
the object will move.
In the third line, I set the current position
of the movie clip (this._x) to continuously increment with
the value of speed. You know I am incrementing because of
the operator += following
the statement this._x.
What is happening?
Let me explain what happens in the
code. As I explained above,
enterFrame continuously executes the code under it.
The speed at which the object moves will be 1. Therefore,
the first time the code runs through, the current X position
of the movie clip increases by a value of 1. The second time
the code runs through, the current X position of the movie
clip increases by another value of 1.
This process gets repeated numerous times (25 times per second to be exact) to simulate movement. The speed at which the code executes depends on the frames per second (FPS) of the movie.
To understand the concepts more, try the
exercises listed in Exploring Further.
|
|
EXPLORING FURTHER |
|
Try the following little modifications and observe the results:
|
|
If you tried the Exploring Further modification mentioned in the above box, your animations will look like the following. Do not hesitate to press the [ start over ] text to view the animation again (or for the first time).
By changing the variable for speed from 1 to 2, we are
changing the speed at which the x position increases. The
higher the number, the faster the movement. Therefore, the
box moves more quickly from the left to the right:
By moving the box to the right and changing speed's
value from 2 to -2, you are reversing the direction at which
the box moves. Anytime you change the sign of a value that
controls movement, you are basically reversing the direction
of movement:
We have basically been dealing with movement in the X
direction. Moving the box in the Y direction is not that
much difficult. Simply change _x to _y to see that the box
move:
If you were really paying attention, you may be wondering why the square is moving up instead of moving down. After all, the speed value is a big -2, and in Geometry, I learned that Y decreases as one moves down. The reason is that Flash does not obey the Cartesian principles that you and I learn in school. In Flash, Y decreases as you move higher and increases as you move lower.
As always, I have provided the source code
for this tutorial. Click the download for Flash MX link
below to download them.
Just a final word before we wrap up. What you've seen here is freshly baked content without added preservatives, artificial intelligence, ads, and algorithm-driven doodads. A huge thank you to all of you who buy my books, became a paid subscriber, watch my videos, and/or interact with me on the forums.
Your support keeps this site going! 😇

:: Copyright KIRUPA 2026 //--