00:00
00:00
Newgrounds Background Image Theme

Sinnymon just joined the crew!

We need you on the team, too.

Support Newgrounds and get tons of perks for just $2.99!

Create a Free Account and then..

Become a Supporter!

AS: Modular Programming

3,716 Views | 7 Replies
New Topic Respond to this Topic

AS: Modular Programming 2005-07-02 07:31:03


AS: Main

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

Response to AS: Modular Programming 2005-07-02 07:36:13


At 7/2/05 07:31 AM, Inglor wrote: 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 ;)

didn't turn out as short as I figured, but then again it explains in a basic way a really importent element in programming, so I'm happy

Response to AS: Modular Programming 2005-07-02 07:37:14


I'm not too familiar with modular programming, but one of my main worries when I read about it was that the .as files would have to be uploaded along with the .swf.

To set your mind at rest, this is not the case; the .as files are compiled into the .swf as it is published.

I really need to get more into modular, I'm definitely a procedural programmer by default =)


- - Flash - Music - Images - -

BBS Signature

Response to AS: Modular Programming 2005-07-02 07:40:22


At 7/2/05 07:37 AM, Denvish wrote: I'm not too familiar with modular programming, but one of my main worries when I read about it was that the .as files would have to be uploaded along with the .swf.

yep, same as OOP, all are compiled into the same .swf files ;) you compile your modules (or classes in OOP) into 1 file, that's the concept ;)

I really need to get more into modular, I'm definitely a procedural programmer by default =)

I think you can go streight OOP, you're definetly good enough for it. Yea, we're all procedural programmers by default since most of our projects aren't big enough for OOP.

Response to AS: Modular Programming 2005-07-03 03:48:04


common denvish, is this really "Advanced" :P?

Response to AS: Modular Programming 2005-07-03 04:02:17


my brain hurts now

Response to AS: Modular Programming 2005-07-03 04:04:03


which part did you not understand?

Response to AS: Modular Programming 2005-12-19 12:00:29


What about #initclip and #endinitclip?