Using Flash Professional, how to import classes from an Actionscript file?

Asked

Viewed 343 times

2

In my project I have the Listloader class, responsible for interpreting a list and uploading files described in it. My goal is to save, this and other classes, in a file extension ". as" and be able to import it in both my current project and others. It is important to mention that this class is not a stage object.

2 answers

4


The Flash import system (in the case of Actionscript 3.0) works by searching in two folders and their subfolders (you can add more folders in the project preferences in the library section): The folder where the Main and the folder where the compiler is installed. In your case, just create a folder, for example, ClassesAuxiliares and paste the file .as inside. To import use the following syntax:

import ClassesAuxiliares.MinhaClasseAuxiliar;

In a generic way, you will provide the path from where the class is.

  • Didn’t get it right ,1°What are the auto import classes is localization? in case they are there are the files that are loaded for all projects? , 2° Besides the previous folders have my sub-folders, which I manage? and in them the files are used only by the project in which the subfolder was configured?

  • 1

    I don’t understand your doubt. But the folders that are already automatically added to search are the project folder and the folder where the compiler is (and all subfolders of these two folders). Already to add more folders that will be checked, you should add their path in the project preferences.

1

Classes imported from Actionscript must be packaged with the path to the directory where they are saved. This is predefined in the class package declaration within your AS code.

Let’s say I have a class called Example that is part of the package examples, so the package code within the class would be:

package examples { //PACOTE DA CLASSE
     public class Example {
          public function Example() {
              //Construtor
          }
     }
}

And the class path in the directory would be raizdoseuswf/examples/Example.as.

To use this class, you need to import it into your project/class using the path and its name at the beginning of the code. See below:

import examples.Example;
var novoExemplo:Example = new Example();

This video can help you a lot.

Browser other questions tagged

You are not signed in. Login or sign up in order to post.