PDA

View Full Version : Find if Mac or PC to launch external file


adam2003w
07-26-2007, 07:15 PM
Find if Mac or PC to launch external file

Is there a way to determine if a user is using a mac or PC projector in order to tell it which method to launch an external file? Example:



on (release) {
if ( Mac ) {
fscommand ("exec", "myAppleScript");
} else if ( PC ) {
fscommand ("exec", "myPDF.bat");
}
}

Ruben
07-26-2007, 08:57 PM
It actually depends on what kind of application you're making (desktop, mobile, etc), and in which version of Actionscript you're writing it (1, 2 or 3)..

- Ruben

adam2003w
07-27-2007, 12:15 AM
this is for a desktop cd-rom

i'm writing in actionscript 2 and using flash 8

any ideas?

CyanBlue
07-27-2007, 12:19 AM
Howdy and Welcome... :)

This should work as long as you are using AS1 or AS2... Just use substr() or indexOf() function with the result of the getVersion() call...
ver = getVersion();
trace(ver);

adam2003w
07-27-2007, 12:27 AM
Also it would be very cool if it could be determined if the script was being run on mac standalone, pc standalone or web swf file like so:



on (release) {
if ( Mac ) {
fscommand ("exec", "myAppleScript");
} else if ( PC ) {
fscommand ("exec", "myPDF.bat");
} else if ( Web ) {
getURL("myPDF.pdf", "_blank");
}
}



I've found an old LoadVariables actionscript here for a mac / pc test:
http://board.flashkit.com/board/showthread.php?t=16998

It didn't work for me I guess 'cause it's actionscript 1. But I found a LoadVars actionscript 2 guide that I'm looking into:
http://www.actionscript4designers.com/wmg3/loadvars_flat_data.html

northcode
08-29-2007, 05:58 AM
Over at FlashKit (http://board.flashkit.com/board/showthread.php?t=718335&highlight=smartexec) I posted a function called SmartExec to solve this problem for someone many moons ago. It gets revived every now and then but the code is oooold. Here's something that will actually work with Flash 8 :)


function SmartExec(target)
{
platform = substring(getVersion(), 1,3);

if (platform == "WIN")
{
// we're running on Windows, target an EXE file
fscommand("exec", target + ".exe");
}
else
{
// we're running on a MAC, target an AppleScript file
fscommand("exec", target + "_script");
}

}
And you would call it like this...

SmartExec("whatever")

On a PC it would try and launch "something.exe" and on a MAC it would try to launch "something_script". Now you can use SmartExec where you used to call the fscommand without worrying about where you're running (as long as you create the necessary target files).

Now, if you want to complicate matters and figure out where your SWF was started from and do something different then the _url property is what you're after. I haven't confirmed this with the latest Flash player or CS3 but...

- on the web it will start with "http://"
- running in a browser from the local file system it will start with "file://"
- running in a standalone EXE it will start with "file:///"

Note: The number of "/" characters differentiates between opening a local SWF in a browser vs. in the standalone player.

This code closes your SWF/app differently depending on where it was started.


if (_url.indexOf("file:") == 0)
{
if (_url.indexOf("file:///") == 0)
{
// standalone player
fscommand("quit", "");
}
else
{
// local SWF in a browser
getURL ("javascript:window.opener=self; window.close();");
}
}

if (_url.indexOf("http://") == 0)
{
// in a browser online
getURL ("javascript:window.opener=self; window.close();");
}