6

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!

Steve Middleton
  • 181
  • 4
  • 13

7 Answers7

4

I know this post has been answered, but I found something simpler. I'm sure the Ant solutions are the way to go, but I didn't feel like messing with ant for my small project. All I really want is to have my html files and swf files in different directories. I guess that's a lot to ask.

I'm building on windows, so I created a simple batch file that performs my post-build steps (namely some move commands). I then created a new builder in flex using windows cmd.exe. I just told it to call the batch file using the /C option. It works perfectly and was very simple to set up. I tried adding screen shots, but I guess I'm too new to the site.

user576154
  • 51
  • 1
  • 4
3

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
  • 2,821
  • 2
  • 20
  • 21
  • This is the best solution, you don't have to replicate the default builder. Ant is noticeably slower than the built in compiler. Plus with this, you don't have to use Ant, you can just specify a BAT file with a few simple commands to run. – davr Dec 03 '10 at 18:39
1

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
  • 8,918
  • 2
  • 37
  • 43
  • 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 Aug 14 '09 at 17:30
  • 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 Aug 14 '09 at 17:31
  • 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 Aug 24 '09 at 17:41
1

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
  • 3,049
  • 1
  • 25
  • 30
  • Because shelling out to ant is a *terrible* substitute for Flex/Flash Builder's internal build system. The internal build system might be horrible, awful and stupid, but at least it doesn't take 15 seconds to build a project when only one file has changed. – David Wolever Dec 06 '11 at 17:49
0

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,160
  • 7
  • 19
0

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
  • 1,309
  • 2
  • 10
  • 20
0

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.

tefozi
  • 5,390
  • 5
  • 38
  • 52