AS3 navigateToURL only works when testing in Flash CC

846 Views Asked by At

I've tried searching stackoverflow to find an answer to this question but so far haven't found anything.

I have a swf file with several movie clips on the stage. When I've managed to create an event where the movie clips swap out to a new movie clip when the user hovers. The problem that I am having is when you click that new movie clip it's supposed to open a URL in a browser window. That happens when I test the movie within Flash CC but when I test it in a browser nothing happens.

Any help for this would be greatly appreciated. I apologize if this question has been asked elsewhere on the site but, as I said, I did a search earlier and didn't find anything.

import flash.events.MouseEvent;

addEventListener(MouseEvent.MOUSE_OUT, gobackAnimation);

function gobackAnimation(event:MouseEvent):void
{
    MovieClip(parent).gotoAndStop(1)
}

addEventListener(MouseEvent.CLICK, openURL);

function openURL(event:MouseEvent):void
{
    ExternalInterface.call("open", "URL I'm trying to open");
    MovieClip(parent).gotoAndStop(1)
}
1

There are 1 best solutions below

2
Anil On

To open a URL you have to use the navigateToURL function as documented here.

It appears that you are using the following code to trigger a URL to open:

function openURL(event:MouseEvent):void
{
    ExternalInterface.call("open", "URL I'm trying to open");
    MovieClip(parent).gotoAndStop(1)
}

However, I don't know where or what this ExternalInterface is and how the call function is built.

If you want to open a URL though, you should be doing something along the following lines:

function openURL(event:MouseEvent):void
{
    var myURL:String = "http://your.url.goes/here";  // set your url here
    var window:String = "_blank"; // you can set this to be whatever you need based on how you want the window opened
    var request:URLRequest = new URLRequest(myURL);
    request.data = variables;
    try {            
        navigateToURL(request,window);
    }
    catch (e:Error) {
        // handle error here
    }
    MovieClip(parent).gotoAndStop(1)
}