This is a follow-up to this two-years old post by Daryl Joseph Ducharme.

While Daryl explains how to use Ant and a *.jsfl file to remotely open Flash IDE, have it compile a given *.fla, and then close, his approach creates a release *.swf file, one that contains no debug information. If you want to actually step-debug trough your code using the Flex Builder’s built-in debugger, some changes are in order.

To start with, we need to use fl.getDocumentDOM().debugMovie() instead of fl.getDocumentDOM().exportSWF() in the *.jsfl file template:

  1. /**
  2.  * Exports file "%fla%" to "%swf%" using current settings.
  3.  */
  4.  
  5. // Open given file:
  6. fl.openDocument ("file:///%fla%");
  7.  
  8. // Export to *.swf, includding debugging information:
  9. fl.getDocumentDOM().debugMovie();
  10.  
  11. // Close the running movie which also ends the debugging session (this didn’t work
  12. // for me):
  13. // fl.closeAllPlayerDocuments();
  14.  
  15. // Close Flash IDE as well:
  16. fl.saveAll();
  17. fl.quit (false);

In my case, a Flash Player window remained open after running the above script in Flash IDE, and there was no way of getting rid of it via the *.jsfl file.

Therefore, I needed to add some code in the build.xml file, in order to close it "by hand". This is what I’ve come up with:

  1. <!– Invokes Flash CS4 IDE an tells it to compile our *.fla file –>
  2. <project default="start">      
  3.         <!– Set Properties –>
  4.         <property name="flashIDE"
  5.                value="my/path/to/Flash.exe" />
  6.         <property name="moviePrefix" value="MyFla" />
  7.         <property name="srcDir" value="path/to/project/source/folder" />
  8.         <property name="destDir" value="path/to/project/bin/folder" />
  9.         <property name="jsflFile" value="compile.jsfl" />
  10.         <property name="jsflTemplate" value="automation.jsfl" />
  11.         <property name="publicUsersFolder"
  12.                   value="path/to/a/public/folder/on/your/system" />
  13.         <property name="batFile" value="killFP.bat" />
  14.         <property name="batFileTemplate" value="automation.bat" />
  15.         <property name="waitTime" value="12" />
  16.  
  17.         <!– Starts the build –>
  18.         <target name="start">
  19.                 <!– After running the debugMovie() command in Flash, Flash Player is
  20.                      launched to show the compiled movie; it will never close by
  21.                      itself, which, in turn, will make the "build" target never exit.
  22.                      This is why we need to run the "waitForBuild" target in
  23.                      parallel. It simply waits a number of seconds, and then forcibly
  24.                      closes all running Flash Player instances.
  25.                 –>
  26.                 <parallel>
  27.                         <antcall target="waitForBuild" />
  28.                         <antcall target="build" />
  29.                 </parallel>
  30.         </target>
  31.        
  32.         <!– Waits a number of seconds before calling the "cleanup" target. –>
  33.         <target name="waitForBuild">
  34.                 <sleep seconds="${waitTime}"/>
  35.                 <antcall target="cleanup" />
  36.         </target>
  37.        
  38.         <!– Attempts to kill all Flash Player instances (see above). –>
  39.         <target name="cleanup">
  40.           <copy tofile="${publicUsersFolder}/${batFile}"
  41.                    file="${srcDir}/${batFileTemplate}" />
  42.           <exec executable="cmd" dir="C:/Windows">
  43.             <arg value="/c"/>
  44.             <arg value="${publicUsersFolder}/${batFile}"/>
  45.           </exec>
  46.         </target>
  47.        
  48.         <!– Invokes Flash IDE with a generated JSFL file as argument. –>
  49.         <target name="build" depends="writeJSFL">
  50.                 <exec executable="${flashIDE}" failonerror="true">
  51.                         <arg value="${srcDir}/${jsflFile}"/>
  52.                 </exec>
  53.         </target>
  54.        
  55.         <!– Generates a JSFL file to pass as an argument to Flash IDE. –>
  56.         <target name="writeJSFL" >
  57.                 <concat destfile="${srcDir}/${jsflFile}">
  58.                         <filelist files="${jsflTemplate}" />
  59.                 </concat>
  60.                 <replace file="${jsflFile}">
  61.                         <replacefilter token="%fla%"
  62.                                    value="${srcDir}/${moviePrefix}.fla"/>
  63.                         <replacefilter token="%swf%"
  64.                                    value="${destDir}/${moviePrefix}.swf"/>
  65.                 </replace>
  66.         </target>
  67. </project>

The batFileTemplate file the build.xml mentions only contains:

  1. :: Kills all running instances of Flash Player. Must be run as
  2. :: administrator, from the local machine. It will NOT work if run from
  3. :: a network location.
  4. taskkill /F /IM FlashPlayer*

All the above worked just fine for my particular configuration, which was: Windows Vista Enterprise 64, Flash CS4, and Flex Builder 3.0.2 (standalone version); it may or may not work in your case.

You’ll definitely need to change a few things: the waitTime property (to accommodate your project compile time); all dummy paths with real ones on your system; and, if you are on a Mac or on a Linux box, then you’ll need to rewrite from scratch the cleanup target.

That’s about it. And, again, thanks Daryl!