AS3 Compiling a program: Difference between revisions

The educational technology and digital learning wiki
Jump to navigation Jump to search
(New page: {{stub}} <pageby nominor="false" comments="false"/> == Compiling an AS3 program with the Flex SDK == There are potentially three ways to compile your first actionscript program: # Compi...)
 
No edit summary
Line 55: Line 55:
[[Category: Actionscript 3]]
[[Category: Actionscript 3]]
[[Category: Tutorials]]
[[Category: Tutorials]]
[[Category: Flex]]

Revision as of 18:30, 31 October 2007

Draft

<pageby nominor="false" comments="false"/>

Compiling an AS3 program with the Flex SDK

There are potentially three ways to compile your first actionscript program:

  1. Compiling with the Flash CS3 Authoring tool
  2. Compiling with Flex Builder
  3. Compiling with the binary mxmlc included in the Flex framework.

Here, we will describe how to compile with mxmlc. This assumes that your Flex framework is properly installed. For information on how to install it on the Adobe Flex page.

Open a text editor, a simple one that will save the text as it appears on the screen, without any formatting. In that new text file, copy the following code:

 package  {

   import flash.display.Sprite;

   public class FilledCircle extends Sprite {

       function FilledCircle():void {

         var circle:Sprite = new Sprite();
         circle.graphics.beginFill(0xFF794B);
         circle.graphics.drawCircle(50, 50, 30);
         circle.graphics.endFill();
         addChild(circle);

       }
    }
 }

Save the file as text and give it the name of "FilledCircle.as". Take good note of the directory in which you save that file. Preferably, put it in a folder quite high up in the hierarchy. We will assume that the file is stored somewhere defined by "\path\to\file\".

On a mac

  1. Open a terminal window. Terminal is an application like any other. To find it, go to the Applications -> Utilities. You should see Terminal.app among the files.
  2. Double click on the application to open it.
  3. At the prompt, type:
 cd \path\to\file\
 mxmlc FilledCircle.as

On a PC

  1. From the Windows start menu, open a command prompt by choosing Start > All Programs > Accessories > Command Prompt.
  2. At the command prompt, change to the C:\Flex SDK 2\bin directory then execute the mxmlc executable on your actionscript file.
 cd C:\Flex SDK 2\bin
 mxmlc C:\path\to\file\FilledCircle.as

The mxmlc executable will compile the program and generate a .swf file name FilledCircle.swf. To run the file, open it in the Flash Player on your desktop or in a web browser that has Flash Player installed. Note that Flash Player 9 needs to be installed to view swf files generated by the Flex compiler.