Hello again, this is an ultra short tutorial on one of the most useful tricks in flash, I hope you enjoy it, you'll be suprised how easy it is after you read it ;)
Programming types:
regular programming
procedural programming (covered in AS: functions)
Modular Programming
Object Oriented Programming (covered in AS: OOP)
Modular programming is a simple and powerful tool, we use the flash #include command to import external files into our SWF, this works with most flash versions (not only 2004) and is very useful indeed
Modular programming means in a very basic way compiling one file out of many source files. It is less advanced and alot simpler then OOP. This presumes knowledge of writing funcctions, but it's not needed
Simple programming with external files
let's say you have a movement script you wrote once, and you want to use it more then once without having to copy it every time, all you have to do is create a new file, name it any way you'd like, and paste the movement script in it (make sure it's extention is .as . now when you want the script to be used all you have to do is use:
#include "scriptname.as"
remmember, no ';' needed, this will auto include your movement script in the location you import it into, it's alot easier to edit many small files then 1 big one, and you can accuretly disable pieces of code out of use. simple eh?
Modular Programming
all you do is create a .as file as you did in the last part, but instead of having actual code in it, you have functions in it, flash isn't truely modular, and therefor we have to use our own syntax, this is what I do
// filename.as - purpose
/*
function fname(params:Type):retType
DOES- what fname does
RETS- what fname returns
GETS- what params fname gets
function fname2(params:Type):retType
DOES- what fname2 does
RETS- what fname2 returns
GETS- what params fname2 gets
......
function fnameN(params:Type):retType
DOES- what fnameN does
RETS- what fnameN returns
GETS- what params fnameN gets
*/
I always start with clear documentation of the actual functions, this helps alot on big files
after that I write the functions themselves.
now basically I have a well documented "Module" a list of functions with a purpose, naturally, I will probebly need that module more then once again since some of the functions might be used again, so this actually saves you from writing again and again the same functions, and shortens your on-screen code. you write a module once and never worry about it again,
I hope this has been helpful, working on my tile tutorial, I don't have flash here so it'll take a while.
Ask any questions ;)
Inglor