Chapter 3: USING START TO OPEN FILES
FROM FLASH APPLICATIONS
The EXEC command can be used to launch executable files like EXE
and BAT files, and even older (DOS executable) COM files, but at
some point a client is going to ask you to open a PDF file or even
a text file. If you've tried this fscommand("exec", "file.txt")
actionScript with EXEC you already know that it
doesn't work. So what can you do?
The most commonly suggested solution is to use START to do it.
Despite the fact that it appears to work, it isn't a very good idea.
If you go to any DOS prompt and type start file.pdf, Windows will
figure out what application should be used to open the PDF file
and launch it with the file name as an argument. The same thing
happens if you just type the file name in the RUN dialog box from
the Windows Start menu.
PLAY
DEMO: » RUN/DOS Example
Disclaimer: Windows XP users need to manually find and install a
Java Virtual Machine plug-in.
This is exactly what we need to open documents in Flash!
The problems begin when you try to call START from Flash. Under
Windows 95, 98 and ME there is actually an external file called
START.EXE that lives in the Windows\Command directory. Under Windows
NT, 2000 and XP the start command is implemented as a command processor
extension, and there is no START.EXE.
If you try to EXEC "START" or "START.EXE" on
95/98/ME it will work but on NT/2K/XP you'll get a dialog box like
this one because START.EXE doesn't actually exist. Flash can only
EXEC files, it doesn't know how to use command processor extensions.

But, there are ways around this. We can ask the command processor
for help.
|
A BRIEF HISTORY OF COMMAND PROCESSORS...
What we call a DOS box today is actually a special program that
was once the only interface between humans and their PCs. It existed
only to process English-like commands into instructions to the operating
system.
There are actually two different command processors around today
command.com and cmd.exe. The command processor used by your system
depends on which version of Windows you're using.
Win9x, and ME use command.com. The .com extension (instead of
.exe) is a dead giveaway (for use old timers) that this is a 16-bit
application, a holdover from the days of DOS and not a true 32-bit
application. You can still find a copy of command.com on NT, 2000
and XP in \WinNT\System32 folder for backward compatibility.
Windows NT, 2000 and XP use cmd.exe. Although they look very similar
when you run them, cmd.exe is a true 32-bit console mode application
and is quite a bit more sophisticated than its 16-bit predecessor.
These two applications share a common heritage and CMD.EXE was
designed to do everything that
command.com could do, just better. The common feature that interests
us is the ability to process command line arguments. You pass arguments
to the command processor using the /C switch like this:
command.com /C
start file.pdf
cmd.exe /C start file.pdf
If you want to open a text file on 95/98/ME this will do the trick:
fscommand("exec",
"command.com" + chr(9) + "/c" + chr(9) + "start"
+ chr(9)+ file.txt");
Although COMMAND.COM exists on NT/2K/XP, and you can launch it,
it's just a copy of the 16-bit command processor. Since START is
implemented as an extension to CMD.EXE on these systems, it doesn't
work! So to use START on NT/2K/XP you have to do this:
fscommand("exec",
"cmd.exe"+chr(9)+"/c"+chr(9)+"start"+chr(9)+"file.txt");
But, CMD.EXE only exists on NT/2K/XP so this is very platform specific.
Unless you're willing to ask your users which system they're using
(and assuming they know) this solution isn't very good. What we
need is a way to call START that will work on all platforms. Luckily,
DOS provides a mechanism to do this, BAT files and Flash can launch
BAT files.
First we need to create a BAT file that can do what the START command
does. That part is easy, just create a BAT file called DOSTART.BAT
put the following line in it:
start %1
Now all we have to do is call the DOSTART.BAT file like this from
Flash and it will work on any platform your user may have.
fscommand("exec",
"dostart.bat"+chr(9)+"file.txt");
The only drawback with using BAT files is the ugly black DOS box
that appears when you use them. You may have heard people mention
using PIF files but they don't work on NT/2K/XP and the best result
you can manage on 95/98/ME with a PIF file is to minimize the DOS
box and make it appear in the Windows taskbar. Better but not perfect.
|