Posts Tagged ‘Flash Executable’

Problem opening web links from a flash CD

Wednesday, March 24th, 2010

Problem: Flash executable file does not open web links on a Mac using getURL / navigateToURL when Safari is not set as the user’s default browser. Users with Firefox get browser focus, but the page doesn’t load.

Reason: Not sure.

Solution: Using ActionScript, determine whether we’re on a Mac or PC, if Mac, run an AppleScript file using fscommand.

AS2:

// what OS are we on?
operatingSystem = System.capabilities.os.substr(0, 3);
trace("I am a " + operatingSystem);

//actions for your button.
myButton.onRelease = function() {
    openMacLink();
}

function openMacLink() {
    //if operating system is Mac, run the openWebpage applescript in your fscommand folder
    if (operatingSystem == "Mac") {
	fscommand ("exec", "openWebpage.app");
    }
    //else, we're on windows and just run regular getURL
    else {
    	getURL("http://www.yourwebaddress.com", "_blank");
    }
}

AS3

// what OS are we on?
var operatingSystem:String=Capabilities.os.substr(0,3);
trace("I am a " + operatingSystem);

//actions for your button.
myButton.addEventListener(MouseEvent.MOUSE_DOWN, openMacLink);

function openMacLink(event:MouseEvent) {
        //if operating system is Mac, run the openWebpage applescript in your fscommand folder
	if (operatingSystem=="Mac") {
		fscommand("exec", "openWebpage.app");
	}
//else, we're on windows and just run regular navigateToURL
        else {
		var request:URLRequest=new URLRequest("http://www.yourwebaddress.com");
		navigateToURL(request, "_blank");
	}
}

Great, we’re halfway done. Now we need to make an AppleScript for each link. On your mac open up the AppleScript Editor (Script Editor prior to Snow Leopard). It looks like this:
script editor

Paste in the AppleScript (change yourwebsitehere.com to what you want to link to):

tell application "Safari"
	activate
	do JavaScript "window.open('http://www.yourwebsitehere.com')" in document 1
end tell

Now save the applescript as an application into your fscommand folder.
Save as an application