ActionScript 3 Hello World using Eclipse on OS X

July 1st, 2006

Here are some quick steps to compiling a simple actionscript 3 swf using Eclipse. This should work using any OS although you would probably need to change the ant build file to use mxmlc.exe if on Windows.

1. Download the Flex 2 SDK from here
2. Move the downloaded files to /Developer/flex_sdk_2
3. Create a simple project in Eclipse
4. Add new file to the project and name it “build.xml”
5. Add this code to the build.xml file:

1
2
3
4
5
6
7
8
< ?xml version="1.0" ?>
<project name="dar" default="build" basedir=".">
	<target name="build">
		<exec dir="." failonerror="true" executable="/Developer/flex_sdk_2/bin/mxmlc">
			<arg line="HelloWorld.as" />
		</exec>
	</target>
</project>

6. Add a new file to the project and name it HelloWorld.as
7. Add this code to HelloWorld.as

1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
package
{
	import flash.display.MovieClip;
	import flash.text.TextField;
 
	public class HelloWorld extends MovieClip
	{
 
		public function HelloWorld()
		{
			var helloDisplay:TextField = new TextField();
			helloDisplay.text = "Hello World";
			addChild(helloDisplay);
		}
	}
}

8. Right click on build.xml and run it has ant build 1. Right click on file -> Run As -> 1 Ant Build
9. Right click on the project folder and select refresh. A file named HelloWorld.swf should be added.
10. Open the swf and watch the hello world goodness be shown.

5 Responses to “ActionScript 3 Hello World using Eclipse on OS X”

  1. John Moscarillo Said:

    Thank you for making this clear. I keep reading about the “Free” flex SDK, but when you try to find out how to use it “free” there is not much documentation. This is a great snippet of educational code. THANK YOU!

  2. Mark Said:

    Thanks for this introduction. I’m currently exploring whether I should buy Flex Builder or just use Eclipse with some addons. I don’t really need the graphical GUI editor from Flex builder but I would want to debug my applications. Is that possible without Flex builder?

    Thanks,
    Mark

  3. Aaron Spjut Said:

    John:
    Glad I could help and thanks for the feedback.

    Mark:
    You can debug your apps without buying flex builder. All of the compile error data will show up in eclipse when you compile. I used only the SDK for a while but finaly broke down and baught Flex 2. I’m very happy with the purchase. I spend much less time getting tools to work and playing with different eclipse plugins.

  4. Adrian Ma Said:

    Hey thanks for that. It was amazing.
    Do you know if there’s anyway to get eclipse to highlight as3 syntax?

  5. Aaron Spjut Said:

    Adrian: There is AXDT ( http://axdt.org/ ) but I have not used it

Leave a Reply