A typical requirement you'll run across when developing CD based Flash projects is the need to open documents from your Flash projector. You can use getURL to open most documents, but sometimes the document opens behind the projector. The EXEC fscommand could be used to launch a helper application, but unfortunately the EXEC fscommand doesn't allow you to pass parameters to external applications so you have no way to tell the outside world which file you want to open.
You can thank the creators of the first Flash virus (SWF/LFM-926) for the fact that every version of the stand-alone Flash player since Flash MX has restricted the use of the EXEC command. This change made it impossible for anyone to create any new Flash based viruses, but it also crippled the Flash projector as a tool for legitimate users by instantly rendering many free projector extension tools useless.
There are four key restrictions that you have to keep in mind when working with the EXEC fscommand and standalone Flash projectors. (i) Executables you want to run via the EXEC fscommand have to be in a special sandboxed folder called fscommand in the same directory as the projector. (ii) You can't specify a path in the EXEC command, just a filename. If the specified file is not found in the fscommand folder, it won't run. (iii) The only argument allowed by the EXEC fscommand is a filename, there is no way to pass arguments to the executables that you want to run. (iv) You can't use EXEC from an SWF file, it will only work from a projector (EXE). The last restriction doesn't really concern us, but if you're trying to test your EXEC calls, being aware of it will save you some frustration.
Update One additional restriction you will have to deal with is the fact that Flash 9 projectors can't launch BAT files on Windows 2000, XP and Vista.
Important If you use SWF Studio then you don't need to read any further. SWF Studio still supports the Flash EXEC FSCommand but the limitations have been removed. Your SWF Studio projectors will be able to pass arguments to external applications and you won't have to put the executables you want to run in the fscommand sandbox folder. SWF Studio extends Flash with new commands like ssCore.Shell.execute and ssCore.Shell.open that make the EXEC fscommand obsolete and give you an unprecedented amount of control over your external applications and documents.
One solution to get around the limitations of the EXEC fscommand is to create one exectuable file for each file that you want to open, but what can you do if you don't know how to make EXE files? Windows and Flash both consider a BAT file as an executable file so the easy solution is to create a BAT file for each file you want to open and EXEC the BAT file from Flash. You don't need to be a BAT file wizard to do this, the simple one-liner below (let's call it mydoc.bat) will do the trick:
That example assumes that both mydoc.bat and mydoc.pdf are in the fscommand folder. You can change the BAT file to launch the PDF file from anywhere you like, as long as you can create a valid path to the file. Now all you have to do is create a BAT file for every file you want to open and call it from Flash like this:
The only problem with this approach is that your user is going to see the ugly black DOS box appear every time they open a file. That's where the proxy utility can help you create a more professional looking end product for your users. Proxy is able to launch BAT files and suppress the ugly DOS box.
When you run the proxy utility, the first thing it does is look at its own name, in this case proxy.exe. It then looks for a BAT file in the same directory with the same base name, i.e. proxy.bat, and runs that BAT file. If you rename the proxy utility to xyz.exe then the utility will look for and try to run xyz.bat. If a BAT file with the same name can't be found, proxy will just fail silently.
By making copies of proxy.exe with different names and creating multiple BAT files you can run as many "hidden" BAT files as you need, neatly sidestepping the Flash limitation on passing parameters to external applications.
Here are step by step instructions to use the proxy utility to open a PDF file without the ugly DOS box.
Create a BAT file called file1.bat that contains just the following line. This is a plain text file that you can create with notepad or your favorite text editor.
Put the BAT file in a folder called fscommand along with a copy of proxy.exe.
Rename the copy of proxy.exe to file1.exe (same base name as the BAT file you created).
Place your PDF document (called file1.pdf) in the fscommand folder with the BAT and EXE files. You don't have to store the files you want to open in the fscommand folder, but for your first test this makes things easier.
Add the following command to your FLA where you want to open the PDF document (probably on a button release action).
Now put your Flash EXE and the fscommand folder on your desktop and run the Flash EXE. When the EXEC command is called your PDF document should open.
The example.zip contains the source for a simple Flash MX projector (projector.fla), a compiled version of the projector (projector.exe) and an fscommand folder with a copy of the proxy utility (renamed to test.exe), the BAT file that the proxy utility will launch (test.bat) and a PDF file (test.pdf) that will be opened when the BAT file is run. Download the example to see the proxy utility in action.
Released: March 30, 2009
Download: proxy.exe (52KB)
This utility has been around for many years now and the Standalone and Applications forum that I moderate at FlashKit is home to a few long running discussions about problems other people have encountered and how the proxy utility has helped them. Definitely worth a read.