Brian Lin
Brian Lin

Reputation: 331

How can I address the as file from another folder?

I usually work with many AS files in the same folder and it is easy to address those files to each other. But I now have a sub folder inside the name folder which stores most of my files; and there is another as file inside that sub folder. How can I change variables of the AS file(inside the sub folder) from the AS files from the main folder and vice verses. Thank you a lot ^^

Upvotes: 0

Views: 139

Answers (1)

shanethehat
shanethehat

Reputation: 15580

You probably need to use the import keyword if I've understood your question correctly. ActionScript files that reside in the same folder are automatically visible to each other, but files in different folders need to be imported. For example:

- name              // folder
    - sub          // folder
        - c.as     // file
    - a.as         // file
    - b.as         // file

In this structure, a can access b (and vice versa) because they are in the same folder, or package. Neither a nor b can access c, becuase it is in a different package (name.sub), and likewise c cannot access a or b.

To make a able to access c, you must import the file first, like this:

//file a.as
import name.sub.c;

Notice that

  1. The path is using dot notation rather than slashes
  2. The path is from the base folder of your project, not relative to the folder in which a resides
  3. the file extension .as is omitted

The same would be done to allow c to access a:

//file c.as
import name.a;

And as a bonus, if you want to import all the files in a package you can use a wildcard selector:

//file c.as
import name.*; //imports a and b

Edit: As Taurayi notes in the comments, correct naming convention is to use lowercase names for folder/package names and to capitalize file/class names, e.g. com.myproject.components.MyComponentClass

Upvotes: 3

Related Questions