PDA

View Full Version : How do you use external files as if they were #included?



xgraves
March 7th, 2010, 01:43 AM
I understand the basics of OOP and classes, but I can't seem to find an answer to something between classes and static functions.

For instance, what if I have a Game.as class that's 1,500 lines long and I want to yank out groups of functions into external files (such as Scrolling.as or DepthManager.as)? Classes don't seem quite right, since I'm dealing mainly with the Game class variables, not separate entities. And putting one function per file would create so many dang files it's arguably worse.

So is there a way to do something like the old #include directive that will tell my Game.as class to just insert the contents of certain files into the middle of the Game.as class so I don't have to monkey with MovieClip(parents) and debugging the theoretical paths of null-object errors?

I'm guessing they took away #include for a reason, but I'm going to wear out my scroll wheel if I don't find a solution soon...

Thanks in advance for any help.

Shaedo
March 7th, 2010, 06:29 AM
include is still around (I presume it's the same)

http://help.adobe.com/en_US/AS3LCR/Flash_10.0/statements.html#include

wvxvw
March 7th, 2010, 07:55 AM
In FD there is region folding, not sure the Builder has one... include is evil...

xgraves
March 7th, 2010, 12:57 PM
D'oh! No freaking way. Thanks Shaedo.

No wonder my searches for "as3 include alternative" came up so meager. And I guess when my books said the #include directive is no longer supported, they literally meant hash include. Either that, or they shared wvxvw's opinion that include is evil and just outright lied to me. (I'm looking at you, AS3 Bible page 45...)

Shaedo
March 7th, 2010, 11:58 PM
I am guessing you are not using CS3 or CS4 where you can highlight a word and press F1 and it takes you to the relevant live doc?

@ wvxvw although I trust you (AS3 wise) implicitly I use include all the time, in particular to switch from 'development' to 'production' code, for example in development I don't want to have anything cached so I have the ubiquitous
'?time='+new Date().getTime()' in my include code used dozens of times but it is commented out until 'production'.

I have also used it because I am lazy and have a file that imports everything I might need so I just include that rather than a mass of import statements. As flash checks and only imports the ones I want it makes no difference at run time.

surely such convenience can't be evil ? :)

wvxvw
March 8th, 2010, 06:15 AM
Erm... use conditional compilation + snippets instead? include is evil because it messes up navigation / autocompletion.