views:

584

answers:

6

Hi there,

How do I add post-build actions in Flex Builder? For example, I'd like my build to work as normal, and execute from the bin folder; but I'd also like a copy of the final SWF to be copied to another folder automatically (I'm sick of doing it myself).

Thanks!

+1  A: 

You'll have to create a custom build script. For whatever reason, the included, default 'builder' is not editable through the interface, so you'll have to replicate a lot of its functionality. Luckily, (or maybe not) Flex Builder uses Apache Ant for its build scripts, so this may or may not be a familiar way to do this for you.

To create a custom build script:

  1. In the Flex Navigator view, select a project and then right-click (Control-click on Macintosh) to display the context menu and select Properties.
  2. Select the Builders properties page. If you're using other Eclipse plug-ins, there may be more than one builder listed. Flex Builder provides a builder named Flex, which you cannot modify.
  3. Select New.
  4. In the Choose Configuration Type dialog box, select the appropriate configuration type. Flex Builder supports the program type. Select it and click OK to continue. From the new builder properties page you define the builder properties and reference the Ant script (an XML file).
  5. Click OK to apply it to the project.

Flex builder is based on Eclipse 3.1, so documentation for Ant integration for that release is relevant here.

Note: Ant support must be enabled in Flex Builder first. I usually use Flex Builder as a plugin, rather than the standalone version, and the standalone version doesn't come with it out of the box. Here's a tutorial on how to do this.

jason
It says that it can't execute the XML file when I try this... when reading the eclipse documentation, it says that the configuration type must be set to Apache Ant, but it's not available in Flex Builder... any ideas?
Steve Middleton
The eclipse doc page I used was: http://help.eclipse.org/help33/index.jsp?topic=/org.eclipse.platform.doc.user/gettingStarted/qs-81_basics.htm
Steve Middleton
Got this to work, but everytime it says "BUILD FAILED", and no more error messages than that... when I run the ant script via the command line it works fine...
Steve Middleton
+1  A: 

Steve,

If you want use Ant in Flex Builder, you may see:http://www.peterelst.com/blog/2006/09/03/flex-builder-2-ant-support/

but I am not sure this is work in flex builder 3 or not.

michael
+1  A: 

Steve,

Here is a bit more detail on the post build script. It will be a simple bat file. For instance add the below line to a simple text file postbuild.bat (name doesn't matter).

copy bin/*.* 'someother location'

This would copy everything in the bin folder to another folder, just change the 'someother location'.

Joel
A: 

You can extend or replace the builder used by Flex Builder 3 with extenal programs - ant is a good choice.

If you run "Flex Builder 3 standalone" (which is a minimalist Eclipse version + the Flex builder plugin) as opposed to the Flex builder plugin in a standard Eclipse, you first need to install ant support. I didn't find ant separately packaged, so I just selected the Java build environment from Help / Software Updates.

Now you can go to your project properties (Right-Click on your Project, Properties) and chose Builders. You'll notice there is a Flex Builder per default, which you cannot remove nor change. However, you can deselect it and you can add other builders.

So in your case: "add" a new builder, ant builder, select a build.xml (can be named differently), preferably from within your project folder, and set the correct targets. This will continue to use the internal IDE builder while running your ant task just before or afterwards. The ordering on the screen will be the build order, which you can change using the arrow buttons.

I used this to copy required libraries into my /lib folder, compile the Flex sources using the IDE build (which has Eclipse-integration with error messages, which a pure ant-based commandline build would miss), and copy the result to a common deploy directory, renaming the wrapper html file in this process.

For details of how to write an ant file, please refer to the ant documentation.

Zefiro
A: 

I would also recommend using ant.

I posted a big article on how to get it set up for flexbuilder here http://dispatchevent.org/mims/ant-for-flex-part-1/ I think there is even an example in my build script of copying files from one place to another after compiling.

Good luck!

Mims H. Wright
+1  A: 

The least elegant solution but it will work on linux.

Create cron task to be executed every minute.

Use cp command with "-u" option. From "man cp".

-u, --update
          copy  only  when  the  SOURCE file is newer than the destination
          file or when the destination file is missing

In crontab -e add

* * * * * cp -u /path/to/bin-debug/*.swf /path/to/destination/

For more elegant solution - Ant the way to go.

zdmytriv