Be a Supporter!

subFolders in Project folder?

  • 599 Views
  • 7 Replies
New Topic Respond to this Topic
DavidHan
DavidHan
  • Member since: Sep. 19, 2011
  • Offline.
Forum Stats
Member
Level 05
Blank Slate
subFolders in Project folder? 2012-01-15 19:00:27 Reply

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?

Torrunt
Torrunt
  • Member since: May. 3, 2007
  • Offline.
Forum Stats
Member
Level 22
Programmer
Response to subFolders in Project folder? 2012-01-15 21:30:03 Reply

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
DavidHan
DavidHan
  • Member since: Sep. 19, 2011
  • Offline.
Forum Stats
Member
Level 05
Blank Slate
Response to subFolders in Project folder? 2012-01-17 00:50:17 Reply

I'm getting error 1172,

definition of ____ could not be found.

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

Torrunt
Torrunt
  • Member since: May. 3, 2007
  • Offline.
Forum Stats
Member
Level 22
Programmer
Response to subFolders in Project folder? 2012-01-17 04:46:58 Reply

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
TapSkill
TapSkill
  • Member since: Aug. 21, 2011
  • Offline.
Forum Stats
Member
Level 04
Gamer
Response to subFolders in Project folder? 2012-01-17 05:47:44 Reply

Very nice explanation, Torrunt.

Sandremss128
Sandremss128
  • Member since: Aug. 22, 2009
  • Offline.
Forum Stats
Supporter
Level 11
Programmer
Response to subFolders in Project folder? 2012-01-17 06:17:53 Reply

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.

DavidHan
DavidHan
  • Member since: Sep. 19, 2011
  • Offline.
Forum Stats
Member
Level 05
Blank Slate
Response to subFolders in Project folder? 2012-01-17 21:17:39 Reply

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!

DavidHan
DavidHan
  • Member since: Sep. 19, 2011
  • Offline.
Forum Stats
Member
Level 05
Blank Slate
Response to subFolders in Project folder? 2012-01-17 21:27:40 Reply

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?