LearningAPI has moved to a new blog!

The learningapi blog has moved to a new URL. These posts will remain here, but all new content has moved to learningAPI.com: Digital Media, Streaming Video & Educational Technology. You may also subscrdibe to the RSS feed for the new learningAPI.com blog.

January 08, 2005

Automated Batch Exporting of Flash .fla files

Macromedia Flash is fast becoming a major platform for web development.  My own group is developing not just content, but tools and even authoring environments using Flash.  But one area where Flash lags far behind is in development process management.  

In particular, my group recently had to re-Export about 600 Flash .fla files while rebuilding a large project.  Unfortunately, Macromedia provides no command-line interface, no batch processing mode that will allow automated, managed build processes such as Apache's ant, which is a staple in most standard software development groups.

A search on the Web and among colleagues found one promising tool - FlashCommand.  This command-line interface to Flash seemed to offer a way to Export Flash via a command script.  Unfortunately, in practice, this didn't work - it launches the Flash GUI, where the export operation stalls on a modal dialg box waiting for input that will never come.  

My solution - it turned out to be fragile but workable for a one-off kind of need.  AutoIt V3 is a scripting tool that allows scripting the Windows GUI.  It depends a lot on window titles and on timing - even the speed of your system can affect the script you'll write for certain operations - but it worked and turned the export of 600+ .fla files into a short, unattended operation.  The script that worked is in the extended part of this posting (click the continue link below"), for those who could benefit from it. 

This is no substitute for a real command-line mode and real 'ant' integration for managing builds, as is so essential in busy development shops doing complex projects. Macromedia needs to step up to the plate and make professional-grade development tools available if it wants to continue to drive towards playing in the "big leagues".

Here's the AutoIt script code. It assumes that all your .fla files are in c:\tmp, and that you're using Flash MX 2004 Professional. You can easily edit the script for different versions or file locations. Just save this text in a file named [something].au3, and then call that file from the Windows command-line.
;code begins here
; Shows the filenames of all files in the current directory
$search = FileFindFirstFile("*.fla") 

; Check if the search was successful
If $search = -1 Then
    MsgBox(0, "Error", "No files/directories matched the search pattern")

While 1
    $file = FileFindNextFile($search)
    If @error Then ExitLoop
  ;c:\tmp in the following line can be edited to your choice of file location
  Run("C:\Program Files\Macromedia\Flash MX 2004\flash.exe c:\tmp\"& $file)
  WinWaitActive("Macromedia Flash MX")
 ; send export command
 WinWaitActive("Export Movie")
; set new filepath and name
 $file = StringTrimRight($file, 4)
 Send("C:\tmp\" & $file & ".swf")
 WinWaitActive("Export Flash Player")
; dismiss export settings dialg
; if you're not using MX 2004 Pro, edit the following line to match the Window title of your version
 WinWaitActive("Macromedia Flash MX Professoinal - [" & $file)
; close .fla file

; Close the search handle
TrackBack URL for this entry:

Listed below are links to weblogs that reference 'Automated Batch Exporting of Flash .fla files' from learningAPI.com: Media and Learning Technology - Larry Bouthillier.
Re: Updating Banner Ads
Excerpt: Haven't dealt with it myself, but was wondering about a very similar question...
Weblog: tribe.net: www.learningapi.com
Tracked: February 15, 2006 01:32 PM