ForumsProgramming ForumGood Programming Technique 101

82 105681
LonLonRanch
offline
LonLonRanch
172 posts
Nomad

Hey Guys, I'd say I'm still fairly new to the forums but I'm checking more and more often, and one thing I have noticed is that the Programming Help section isn't very active. So I thought I would add my 2 cents and share some of my AS programming experience.

I've been programming actionscript for about 3-4 years now and have even been through 2 ArmorGames challenges. I've been asked by a lot of people for some coding help over my time and, well, I see a lot of times that I code quite a bit differently then they do, and a lot of that is because they are:
1.Still new to Actionscript
2.Have learned only from online tutorials
3.Are used to coding with what works instead of what works best.

So, what I decided to do here is to share with you what I have learned over the years to be Good Programming Technique. So before I start this first one off take note:
This is being coded is Actionscript 2.0 (I still have to fully embrace AS3 although I highly encourage learning it)
Also, this is what I have personally learned from my experience, you may disagree, that is fine, actually if you think I'm wrong let me know so that we can all learn because there is no reason to code ONE way.

Ok so after that intro this is what I have to share with you.

Coding on the Main Timeline

The more complex your game gets, you're going to have more MovieClips, Layers, Frames, lines of code, etc. And with that, it will be harder to organize everything. Which is why it is always good technique to code on the main (or _root) timeline. Now some of you may not even know it, but you can actually control every aspect of your game by coding into the the first frame (not movieClip, frame) of your game. For example, on my latest game I had right around 2000 lines of code on the very first frame.

2000 lines on the same frame!?

Yes. You may be thinking right now, How? Well, there are 2 very very important coding methods I use when I program and they both make use of that frame. The first one, which I'm going to explain on this post is calling movieClip's (onEnterFrame) method from the main timeline instead of on the instance of the movieClip itself. I'm sure you are very used to coding with:
onClipEvent(enterFrame) -What I'm telling you is that I don't do that.

You can do onClipEvent(enterFrame){ outside the movieClip?

Yes, yes you can. And here is how:

on the main timeline for a movieClip with the instance of myClip you would have something like:

myClip.onEnterFrame = function():Void{
Which would be the same doing a onClipEvent(enterFrame){ on the myClip movieClip, you just have to make sure you have the instance name (in Properties) set to 'myClip' and that it is on the main timeline.

-If it is not in the main timeline, lets say its in a movieClip called 'otherClip' you simply have to add a bit of code:
otherClip.myClip.onEnterFrame = function():Void{

Umm ok, but I still don't see why you do this...

Fine fine, I understand this might be a little confusing at first, but in time I'm sure it will make sense, it might take a little trial and error. The reason I say it is good technique is that having all of your code on the main timeline makes it very easy to keep your code organized and easy to locate. If you have several movieClips/Frames/Layers in your game that you want to apply code to, it going to get confusing. Where did I put that clip? Where is the code that deals with the hitTest? What frame is it on? etc, when you code in one place you don't lose, forget, or repeat code. Its all in the same place so it is easy to work with, and if you ever code with with someone else it will make their lives a lot easier because they won't be looking all over for code they don't even know exists.

Alright, so just a few notes to end on: (gosh this post long, sorry)

It is always a good idea to code on the main timeline.
You can save lots of lines of code and better organize your code by calling .onEnterFrame functions (functions are a very very big part of coding as well, if you don't know about them I'm sure I'll make a topic on it someday)
Even if you code AS3 you can still practice this.

Let me know if something doesn't make sense, I'm sure it may be quite confusing.

  • 82 Replies
7432200
offline
7432200
134 posts
Nomad

I wish it had more script on it to copy

Google567
offline
Google567
4,013 posts
Farmer

I wish I could get into making games.
I think it'll never happen though.

Google567
offline
Google567
4,013 posts
Farmer

Does it get easier or always hard.

Annihalation
offline
Annihalation
479 posts
Nomad

Depends on what kind of learner you are. If you learn by reading (like me) you could get good at it simply by reading tutorials, getting the correct result, and then tweaking it and getting your desired result. If you learn by listening (also like me), It would be good to get a friend or someone who is experienced to help you learn. If you learn by doing, Trial and error is not bad, as long as you save copies of your work often!

The main obstacle in coding is time. You need to be dedicated and have at least a little bit of time to spend on coding, at least a couple times a week if you want to become a serious game maker. I stopped working on it for a month and that's all it took for me to forget a lot of what I learned.

Metaknight100
offline
Metaknight100
3 posts
Nomad

I guess if I really want to make games,I gotta take extra school time.

Google567
offline
Google567
4,013 posts
Farmer

Thanks, I can see all those points.
But really on the internet, whats the difference between reading and listening?

JustScott
offline
JustScott
96 posts
Nomad

wait wat... im confused... im going to sleep ... wake me up when this is all in one clear post

jdconoly
offline
jdconoly
1 posts
Nomad

thx man i need some help

rhp
offline
rhp
4 posts
Nomad

what code sould you put in to make a button to make a button code to go to a website.

Darkroot
offline
Darkroot
2,763 posts
Peasant

Don't forget writing comments in your code and spacing properly.

rhp I think it is..
on (release) {
getURL ("javascript:NewWindow=window.open('somewebsite','newWin','width=400,height=300,left=0 ,top=0,toolbar=No,location=No,scrollbars=No,status =No,resizable=Yes,fullscreen=No'; NewWindow.focus(); void(0);"
}
You can do some edits on that

Adikaaaa
offline
Adikaaaa
6 posts
Nomad

Good job, this may be very usefull to me!

Aang65
offline
Aang65
1 posts
Nomad

does anyone want to know how to make a custom cursor???

asgerregsa
offline
asgerregsa
7 posts
Nomad

It might be very well organized if you code on the first frame only but I still put some code on the movieclips and some code on some different frames because on my computer (Windows Vista, 3GB RAM) it starts lagging a lot when there is only like 100 lines of code on a frame.

asgerregsa
offline
asgerregsa
7 posts
Nomad

does anyone want to know how to make a custom cursor???


Yes and here is how:

You make a movieclip that's gonna be your cursor. Let's say you give it the instance name of "cursor".
Put "cursor" on the stage.
On the frame, put this code:

Mouse.hide();
startDrag(cursor, true);


That was a little off topic but I hope it helped
Ancellius
offline
Ancellius
1 posts
Nomad

First time even reading about ActionScript... but it's all very interesting. I just used about 5 hours of my life and 10 billion brain cells memorizing all of this... now ijust need to get a flash program to start doing it myself.... got an artist, and a musician...guess i've gotta be a programmer haha. Thanks guys, this really REALLY does help.

Showing 31-45 of 82