00:00
00:00
Newgrounds Background Image Theme

MutantZulu81241 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!

subFolders in Project folder?

999 Views | 7 Replies
New Topic Respond to this Topic

subFolders in Project folder? 2012-01-15 19:00:27


Hi.

I'm using AS3 OOP.

If i want to organise my .as files in my project folder into many subfolders such as menu items, is there a special procedure I have to follow to let flash know where my seperate .as files are?

Response to subFolders in Project folder? 2012-01-15 21:30:03


Just change the package name at the top of the .as files to reflect their location.
Example: a class in the folder "classes/characters/enemies" would have the package "classes.characters.enemies".

And when you import them you just refer to them like that.

import classes.characters.enemies.wilddog;

BBS Signature

Response to subFolders in Project folder? 2012-01-17 00:50:17


I'm getting error 1172,

definition of ____ could not be found.

BTW i'm importing this to my document class right?

Response to subFolders in Project folder? 2012-01-17 04:46:58


At 1/17/12 12:50 AM, DavidHan wrote: I'm getting error 1172,
definition of ____ could not be found.

Is the file name the same as the class inside it?
Example: the wilddog class would be in the file wilddog.as

If that's not the problem then maybe you made a typo or something somewhere.

At 1/17/12 12:50 AM, DavidHan wrote: BTW i'm importing this to my document class right?

Yeah, or where ever you are using the class.

--------------

Here's an example showing a possible folder structure:
Image (below as well)

Then inside enemy_fisherman.as

package classes.characters
{
	...
	public class enemy_fisherman extends enemy
	{

and then where ever I want to use this class I will simply import it like this:

import classes.characters.enemy_fisherman;

or

import classes.characters.*;

which import all the classes in that package/folder that are being used.

subFolders in Project folder?


BBS Signature

Response to subFolders in Project folder? 2012-01-17 05:47:44


Very nice explanation, Torrunt.

Response to subFolders in Project folder? 2012-01-17 06:17:53


unless you are using a barbaric IDE, importing will be taken care of for you. You should just put classes that are related into the same folder for your own sanity. When you get a little bit more advanced with using packages you may use internal variables that only classes with the same package can access.

Response to subFolders in Project folder? 2012-01-17 21:17:39


Thanks Torrunt. I'm using flash IDE btw.

As a test, I tried putting a class file into a folder called MenuButtons, then in the .as file of that class, i put

package MenuButtons {

I did not get an error, so I guess that part is good, but when I tested my project, the classfile didn't run. I tested a trace(); in the constructor, and it didn't run.

Do i need to import in flash IDE?
when do I need to import? do I have to do it everytime or just once?
thnks!

Response to subFolders in Project folder? 2012-01-17 21:27:40


Whoops, turns out the class is one that is dragged onto the stage using flash instead of being created at runtime. Does that make a difference? has flash already imported it now? where do i set the new classpath then?