Vous êtes sur la page 1sur 8

Basic AS2 tutorial

Basic AS2 tutorial

Basic AS2 tutorial


First of all, it is explained how to prepare Eclipse in case of creating a project with Eclipse for the first
time. After that you will create your first project and therein a new class . At last, it is shown how to
run your project .

Preparing the workbench

Make sure that several paths are set properly before creating your first AS2 project. Therefor open
preferences and choose "FDT->Tools".

At first, make sure that the paths to the installed FlashIDE are set properly. Under "FDT->Tools->Flash"
you can set up the path to the local installation of your FlashIDE if necessary and define the correct
Flash Player to run your SWF files. Make sure that several paths are set properly before creating your
first AS2 project. Therefore open preferences and choose "FDT->Tools".
At first, make sure that the paths to the installed FlashIDE are set properly. Under "FDT->Tools->Flash"
you can set up the path to the local installation of your FlashIDE if necessary and define the correct
Flash Player to run your SWF files.

FDT uses this information to compile your files in case if you intend to use your FlashIDE for this
purpose.

A quicker alternative offers MTASC. MTASC is an AS2 compiler which can also be used out of FDT.
Therefor please choose "FDT->Tools->MTASC".

Simply adjust the definition of the path to MTASC's executable file.

1
Basic AS2 tutorial

Creating your first project

In order to set up a new project, please use the wizard that provides the appropriate support. There
are several ways to activate the wizard. In the following example the Flash Explorer is being used.

Right click with your mouse in your Flash Explorer window and choose "New->New Flash Project".
When the wizard opens for a new project to be created you have to enter the project's name and
select the language version. In this example we name the project "Test" and choose "Action Script 2"
as language version.

Please press "Next" to continue with the following step.

Within the second step you create the source folders for your project. FDT has already created a
special source folder, the so called Core Library . This contains all basic flash classes as for example
the definition of "number" or "object". Apart from that,

2
Basic AS2 tutorial

FDT creates an additional source folder in which you can create your own classes. Click on "Finish"
and the project is being created.

Create your first class

In order to create a first class the context menu of the Flash Explorer could be used. Using the global
buttons of Eclipse, however, is a little bit faster. First of all, select the source folder "src" and click the
button.

A dialog window appears helping you to create a new class. Name your class "Test1". At this point,
further characteristics such as super class and implemented interfaces could be specified; though,
for a start, we leave it at the name.

Click on "Finish" and the class is being created. An editor opens automatically and the class appears
in the Flash Explorer.

3
Basic AS2 tutorial

The class already contains a comment. If and in which form it appears can be defined in the
preferences (" Customize your code Style "). Here the exact formatting, as for example the
whitespace to be generated or parentheses to be used, can as well be determined.

Run your first class

Now, please enlarge your class by a few lines so that you get to see results when executing.
class Test1 {
public static function main(container : MovieClip) : Void {
Stage.align = "TL";
Stage.scaleMode = "noScale";
container.createTextField("tf", 1, 0, 0, 100, 100);
var tf : TextField = container["tf"];
tf.text = "Hello World";
}
}

FDT offers several possibilities to compile ActionScript (read more under " Running and building your
programs "). MTASC, a free disposable ActionScript compiler is especially fast. In order to use that
you have to create a launch configuration. Herein, all data is saved that is necessary to execute the
program. First of all, open the "run configuration" dialog window.

4
Basic AS2 tutorial

Here please choose the "FDT MTASC" and click the "New" button. Assign a name as for example
"Test1" to the configuration and choose your project from the first tab and afterwards the created
class by clicking the "Browse..." buttons.

Go to the tab "Miscellaneous" and activate the check box "Start SWF after compilation". Click on the
"Browse..." button and search for the project directory. Enter the name "default_mtasc.swf" as file
name (this is the SWF being created as default which can be changed on the tab "MTASC-
Arguments").

5
Basic AS2 tutorial

Press the "Run" button. The project will be compiled, the SWF created and the project is displayed in
the internal SWF viewer.

Vous aimerez peut-être aussi