Be a Supporter!

AS: Modular Programming

  • 2,684 Views
  • 7 Replies
New Topic Respond to this Topic
Inglor
Inglor
  • Member since: Jan. 26, 2003
  • Offline.
Forum Stats
Member
Level 17
Blank Slate
AS: Modular Programming 2005-07-02 07:31:03 Reply

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

Inglor
Inglor
  • Member since: Jan. 26, 2003
  • Offline.
Forum Stats
Member
Level 17
Blank Slate
Response to AS: Modular Programming 2005-07-02 07:36:13 Reply

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

Denvish
Denvish
  • Member since: Apr. 25, 2003
  • Offline.
Forum Stats
Member
Level 46
Blank Slate
Response to AS: Modular Programming 2005-07-02 07:37:14 Reply

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
Inglor
Inglor
  • Member since: Jan. 26, 2003
  • Offline.
Forum Stats
Member
Level 17
Blank Slate
Response to AS: Modular Programming 2005-07-02 07:40:22 Reply

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.

Inglor
Inglor
  • Member since: Jan. 26, 2003
  • Offline.
Forum Stats
Member
Level 17
Blank Slate
Response to AS: Modular Programming 2005-07-03 03:48:04 Reply

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

Furnix
Furnix
  • Member since: Jun. 30, 2005
  • Offline.
Forum Stats
Member
Level 09
Blank Slate
Response to AS: Modular Programming 2005-07-03 04:02:17 Reply

my brain hurts now

Inglor
Inglor
  • Member since: Jan. 26, 2003
  • Offline.
Forum Stats
Member
Level 17
Blank Slate
Response to AS: Modular Programming 2005-07-03 04:04:03 Reply

which part did you not understand?

Fire
Fire
  • Member since: Oct. 29, 2003
  • Offline.
Forum Stats
Member
Level 15
Programmer
Response to AS: Modular Programming 2005-12-19 12:00:29 Reply

What about #initclip and #endinitclip?