I would suggest moving away from programming in the timeline, (if that's what you're doing now) as it's not the most organized or optimized form of programming. Everything should be done as separate ActionScript files.
Everything I'm about to type is a lot of setup. It may seem like a confusing process at first, but once you start cranking out games, it becomes a very quick process.
So, to start out, make a new folder and call it whatever you want.Then, open up Flash and create a new ActionScript 3.0. (Just like you normally would.) Save that file into the folder you created. (From now on, I'll be calling this file the Main Fla) Then, inside the folder you made, make a new folder called "Classes". In Flash, go to File > New and make a new ActionScript 3.0 Class. Immediately save the file into the Classes folder that you created. (From now on, I'll be calling this file the "Main Class") Do not use any spaces or non-alphanumerical things in the name.
Now go back to your Main Fla and go to File > Publish Settings. Then click on the little image that looks like a wrench near the top of the window that pops up. Now, in the new window that pops up, type in the name of your Main Class. Then, if you look below that, you should see a few tabs, such as "Source Path" and "Library Path" etc. Make sure you have Source Path selected. This tab window lists all of the files that your Main Fla will reference while coding. It's basically the central hub that tells the Main Fla where everything is. If there is anything in the tab window, (There's probably one thing that has a folder with a . next to it) click on it and press the "-" button. Then click on the folder icon next to the "-" button and browse to the Classes folder that you created. Select the Classes folder and hit ok.
All you were doing in all of that was telling the Main Fla which file it should start up first and where to find all of the files that you'll be making.
Now go to the Main Class file that you created and we'll actually start coding. :D
To start out, type (And I mean type. Don't copy and paste. You won't remember anything that way) the following:
package {
import flash.display.MovieClip
public class extends MovieClip {
public function () {
}
}
}
That's the base code for pretty much every class you'll be making as you start to learn about classes. Obvisouly, replace with whatever you named the Main Class file. From there, you're coding pretty similar to how you would on the timeline. If you happen to find the need to make more classes than just the Main Class, (You may not for every project, but most of them call for more than one) make a new ActionScript 3.0 Class file and save it into the Classes folder.
I'll just write a quicky program to get you started.
Main Class: (Called Main)
package {
import flash.display.MovieClip
public class Main extends MovieClip {
var theball:Ball = new Ball(100,100)
public function Main () {
addChild(theball)
addEventListener(Event.ENTER_FRAME, enterframe)
}
public function enterframe (event:Event) {
theball.y++
}
}
}
Ball Class: (Called Ball)
package {
import flash.display.MovieClip
public class Ball extends MovieClip {
public function Ball(xPos, yPos) {
x = xPos
y = yPos
}
}
}
So all I have here are two classes. One is the main class, and the other is the ball class. The main class is creating a new object of the ball class and adding it to the stage. Then every frame, it's moving that object down 1. The Ball class has parameters that lets me set its original x and y positions. When I created the object "theball" I set it's starting coordinates to 100,100. Try testing something out like that yourself and seeing if it works. :)
Oh, quick side note. You won't actually see anything going on when you run the game, since we didn't make any images. I don't know if you know how to do that or not, so I'll just go ahead and tell you anyway. Since we have a ball class, draw and circle and then select it. Go to Modify > Convert to Symbol. Name the symbol "Ball", make its type a MovieClip, and then go down to advanced and check Export for ActionSctipt. Then make sure next to Class, it say "Ball" and then click ok. Now Flash knows to put the image of the ball wherever the ball object is on the stage.
If you run into any problems or errors, feel free to post back.