2008/07/04 14:30

How to develop for Flash&Flex on any OS, for free

This guide isn’t particularly definitive, mostly because right now all the tools needed lack real cohesiveness, paticularly on Unix. This is simply how I pulled everything together to make things work using freely available software.

Step 1: Get Eclipse

Download Eclipse. Put it somewhere. If you’re using Linux, install using it using your favorite package management software. This guide will probably only work if you use 3.2 or above. (NOTE: If you use Ubuntu for this, then at the time of this writing Eclipse 3.2 is only in the “universe” repository, you can enable “universe” using Synaptic)

Step 2: Pull Flex together

Download the Flex 2 SDK. You’ll probably need to sign up for an account. Extract it. Download the Flex Ant Tasks and extract flexTasks.jar (in lib) to lib in your Flex directory.

You’ll need to set up the standalone player so you can debug your swf files. This varies between Operating Systems…

  • Linux: Download the Linux Flash Players and extract the debug player (in standalone/debugger/flashplayer.tar.gz) to bin in your Flex folder. Rename the the debug player (which is named flashplayer) to gflashplayer. You can also install the debug plugin for browsers if you’d like.
  • Windows: Run SAFlashPlayer.exe (in your Flex directory, under player/debug/) and it will register itself as the debug player. There’s also two installers for debug plugin if you care to install them too.
  • OSX: Use SAFlashPlayer.dmg (in your Flex directory under player/debug/) to install the debug player. There’s an installer for debug plugin there too.

Step 3: Create a project

Create a general project in Eclipse and put various Actionscript-related files there. Create a file called build.xml. This will be your Ant build file, and what you’ll use to compile your project. There’s more details on Ant here. Here’s a sample…

<project name="sample" basedir="." default="build">

<property name="FLEX_HOME" value="/path/to/flex"/>
<taskdef resource="flexTasks.tasks" classpath="${FLEX_HOME}/lib/flexTasks.jar" />
<target name="build" description="Build">

<mxmlc file="example.as" output="bin/example.swf" use-network="false" compiler.optimize="true">

<load-config filename="${FLEX_HOME}/frameworks/flex-config.xml"/>
<source-path path-element="${FLEX_HOME}/frameworks"/>
<source-path path-element="/path/to/as3-library"/>

</mxmlc>

</target>

</project>

The taskdef entry and the FLEX_HOME variable need to be there in order to use the mxmlc task to compile swf files. On Linux the property use-network="false" mysteriously allows the compiled swf to access files on your computer, without it an error is thrown when you try to access a file

Step 4: Syntax Highlighting (optional)

There is no free Actionscript 3 syntax highlighter, and the only one for Actionscript 2 is poor (sorry guys). Luckily Actionscript resembles heavily resembles Java. Simply associate .as files with the Java Editor in Eclipse (Window->Preferences, then General->Editors->File Associations) and hope nobody notices.

  • To change the formatting (particularly tab width) go to the Formatter (Java->Code Style->Formatter) and toy with the settings until it looks like your preferred coding style.
  • To change the colors go to the Syntax Coloring section (Java->Editor->Syntax Coloring)
  • To prevent Java from making suggestions, go to auto-activation (Java->Editor->Content Assist) and remove any characters in the “Auto activation triggers for Java” section.

Step 5: Compilation

Open the Ant viewer in Eclipse (Window->Show View->Ant) and drag your build.xml file to it. Use it to run build files.

Step 6: Debugging Preparation

You’ll need another target in your build.xml used for creating a secondary swf for debugging.

<mxmlc file="example.as" output="bin/example-debug.swf" use-network="false" incremental="true" debug="true">

Run this target whenever you want to update the debug version of your swf. The debug="true" property needs to be there in order for it to work. Make sure the output/swf file has a different name than your optimized build since this version is purely for debugging and will be slower.

Step 7: Debugging

Open the External Tools window in Eclipse (Run->External Tools->External Tools…). Select “Program” and create a new configuration. Set “Location” to the location of fdb, the Flash debugger (it’s in your Flex directory, under bin). The working directory should be the location of your compiled swf files. The only argument should be the file name of the swf file you’ll be debugging.

Run the external tool configuration you just created (there’s a button for it on the toolbar) whenever you want to debug the swf. When you do a console will open up, and the debugger will start. The Flash Player window will open, but it will remain frozen until you type “continue” in the Eclipse console. All output (trace) will appear in the console. If you familiarize yourself with fdb you can make use of many more features. To stop debugging, type “exit” in the console or just close the player window and terminate fdb.

원문: http://blog.brokenfunction.com/2007/01/29/how-to-develop-for-flash-on-any-os-for-free/

Trackback 0 Comment 0