…remotely compile FLA files for Flex Builder debugging
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:
-
/**
-
* Exports file "%fla%" to "%swf%" using current settings.
-
*/
-
-
// Open given file:
-
fl.openDocument ("file:///%fla%");
-
-
// Export to *.swf, includding debugging information:
-
fl.getDocumentDOM().debugMovie();
-
-
// Close the running movie which also ends the debugging session (this didn’t work
-
// for me):
-
// fl.closeAllPlayerDocuments();
-
-
// Close Flash IDE as well:
-
fl.saveAll();
-
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:
-
<!– Invokes Flash CS4 IDE an tells it to compile our *.fla file –>
-
<project default="start">
-
<!– Set Properties –>
-
<property name="flashIDE"
-
value="my/path/to/Flash.exe" />
-
<property name="moviePrefix" value="MyFla" />
-
<property name="srcDir" value="path/to/project/source/folder" />
-
<property name="destDir" value="path/to/project/bin/folder" />
-
<property name="jsflFile" value="compile.jsfl" />
-
<property name="jsflTemplate" value="automation.jsfl" />
-
<property name="publicUsersFolder"
-
value="path/to/a/public/folder/on/your/system" />
-
<property name="batFile" value="killFP.bat" />
-
<property name="batFileTemplate" value="automation.bat" />
-
<property name="waitTime" value="12" />
-
-
<!– Starts the build –>
-
<target name="start">
-
<!– After running the debugMovie() command in Flash, Flash Player is
-
launched to show the compiled movie; it will never close by
-
itself, which, in turn, will make the "build" target never exit.
-
This is why we need to run the "waitForBuild" target in
-
parallel. It simply waits a number of seconds, and then forcibly
-
closes all running Flash Player instances.
-
–>
-
<parallel>
-
<antcall target="waitForBuild" />
-
<antcall target="build" />
-
</parallel>
-
</target>
-
-
<!– Waits a number of seconds before calling the "cleanup" target. –>
-
<target name="waitForBuild">
-
<sleep seconds="${waitTime}"/>
-
<antcall target="cleanup" />
-
</target>
-
-
<!– Attempts to kill all Flash Player instances (see above). –>
-
<target name="cleanup">
-
<copy tofile="${publicUsersFolder}/${batFile}"
-
file="${srcDir}/${batFileTemplate}" />
-
<exec executable="cmd" dir="C:/Windows">
-
<arg value="/c"/>
-
<arg value="${publicUsersFolder}/${batFile}"/>
-
</exec>
-
</target>
-
-
<!– Invokes Flash IDE with a generated JSFL file as argument. –>
-
<target name="build" depends="writeJSFL">
-
<exec executable="${flashIDE}" failonerror="true">
-
<arg value="${srcDir}/${jsflFile}"/>
-
</exec>
-
</target>
-
-
<!– Generates a JSFL file to pass as an argument to Flash IDE. –>
-
<target name="writeJSFL" >
-
<concat destfile="${srcDir}/${jsflFile}">
-
<filelist files="${jsflTemplate}" />
-
</concat>
-
<replace file="${jsflFile}">
-
<replacefilter token="%fla%"
-
value="${srcDir}/${moviePrefix}.fla"/>
-
<replacefilter token="%swf%"
-
value="${destDir}/${moviePrefix}.swf"/>
-
</replace>
-
</target>
-
</project>
The batFileTemplate file the build.xml mentions only contains:
-
:: Kills all running instances of Flash Player. Must be run as
-
:: administrator, from the local machine. It will NOT work if run from
-
:: a network location.
-
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!
