Back in my University days having a Mac was not always fun in a Windows dominated campus. I always had to ensure that my disc’s were able to be read in a Windows machine, even though they were burned on a Mac. After looking over some of my files I decided to share with the world some of the code snippets I found along the way. This posts concerns creating cross plaform Flash CD-Roms, inparticular opening folders from projectors.
Auto Run
Due to a security vulnerability in OS X 8 (i think!) the auto run feature was disabled on a Mac, however there was an option to open the root folder by default (a really easy option using Toast Titanium).
In Windows an autorun.inf file should be created. This can display an icon and launch an .exe or .bat file as well as set the label for the disc.
[autorun]
open=myApp.exe
label=My App
icon=myApp.ico
As previously mentioned by using Toast Titanium on the Mac it is very easy to open up a folder containing the .app file to launch. You can also specify which folders and files should be seen by each operating system.
Opening Folders from Flash
Opening folders or files from Flash is a bit of a work around these days. Before Flash MX 2004 it was relatively easy to do, but after a security vulnerability this freedom was closed down. You now need to place your .exe or .app files in a folder called fscommand. It has to be this AND ONLY this. This fscommand folder must be at the same level as the Flash projector. i.e
My Folder >
myProjector.exe
myProjector.app
fscommand
You may be thinking “how do I open up an application from here then?”
The answer is to use a helper file; in Windows an .exe and in Mac an AppleScript file saved as an .app. I will show you how to open a folder from a Flash projector as this was an issue I had problems with as a student when trying to create an interactive CV. There are various ways, but these methods seem the most robust. Both methods use the exec parameter from the fscommand:
fscommand(“exec”,”AppName”)
Windows
In Windows the process is a bit of a bitch. 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.
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:
start mydoc.pdf
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:
fscommand(“exec”, “mydoc.bat”);
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.
The proxy file will launch a .bat file with the same name. Inside the .bat file the following code should be placed. This will simply open up an Explorer (not Internet Explorer) Window for the specified folder. The path is relative to the .bat file.
%SystemRoot%\explorer.exe “FolderName“
The proxy.exe file needed can be found in the zip below. The only rule is that the .exe and .bat file must have the same name. To open up multiple folders, simply create new .bat files and copy/rename the .exe to suit.
Mac
Doing the same thing in Mac is a bit easier. You simply need to use an AppleScript file. The code below will open a new Finder window displaying the contents of the specified folder on the specified disk. Replace DiskName with the name of the disk. This is better than Windows as the name of the disc will never change, where you can never be certain of the drive letter.
tell application “Finder”
activate
make new Finder window to disk “DiskName“
set target of Finder window 1 to folder “FolderName“ of folder “fscommand” of disk “DiskName”
end tell
If you don’t know how to write AppleScript, don’t fear – just follow these steps (you will need a Mac, or know somebody that has one!):
So now we have the command for Flash and the Windows and Mac helper files to launch our folders. The next step would be to create some actionscript that will handle launching our folders. Lets assume that on our disc we want to open five folders. For ease of use, name these folders – folder0, folder1, folder2, folder3, folder4.
We can then set up a loop and attach to buttons to launch a file.
Telling the difference
Use this script below to call either the Windows .exe or the Mac .app helper file:
if (platform==”WIN”){
fscommand(“exec”, which + “.exe”);
}else{
fscommand(“exec”, which);
}
That’s it, you should now be set to get creating cross platform CD’s. The zip file below contains a sample .exe, .bat and Applesctipt file.
Download source files crossplatformfiles