0

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)
}
Anil
  • 2,539
  • 6
  • 33
  • 42
  • You will have to share the code in question before someone can help you. For tips on how to ask better questions on SO, please visit [this](http://stackoverflow.com/help/on-topic) link. Cheers. – Anil Feb 24 '14 at 00:22
  • My apologies. There is the code that I used. – user3344673 Feb 24 '14 at 09:04
  • I've provided an answer, but without seeing the code you specified with the call `ExternalInterface.call("open", "URL I'm trying to open");` it's hard to see if there is a problem with how you are opening URLs. – Anil Feb 24 '14 at 09:20

1 Answers1

1

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)
}
Anil
  • 2,539
  • 6
  • 33
  • 42
  • Thank you for the help. I'm actually new to AS3 coming out of AS2 (I haven't been doing Flash programming for quite a while but a friend asked me to make something in Flash for them) so I was lost on how to make it work. At first I tried using the navigateToURL method but I didn't define the window as a variable. I'll try that and see if it works. As for the ExternalInterface, that bit of code you saw is all I used (minus the url), I don't have any other code relating to that function. – user3344673 Feb 24 '14 at 17:00
  • @user3344673 Well just so you know the line of code, `ExternalInterface.call("open", "URL I'm trying to open");` won't open a URL. You have to set it up the way I documented in the answer I posted. This isn't to say that you can't centralize that into it's own function for reusability, but at least you have a working example. The `window` variable is an optional parameter to the `navigateToURL` function, but I felt it was worth mentioning because it will dictate which window your URL will open in which can be important. If you have any questions about my code, please let me know. – Anil Feb 24 '14 at 17:07