The following example shows how you can open new browser windows from Flash Player using the navigateToURL() method in ActionScript 3.0 or the getURL() method in ActionScript 2.0.

Full code after the jump.

In ActionScript 3.0 you can use the navigateToURL() method to open a new browser window, as seen in the following example:

// ActionScript 3.0
/* Requires
 * - Button symbol on Stage with instance name "buttonSymbol"
 */
buttonSymbol.addEventListener(MouseEvent.CLICK, buttonSymbol_click);
 
function buttonSymbol_click(evt:MouseEvent):void {
    var req:URLRequest = new URLRequest("http://www.adobe.com/");
    navigateToURL(req, "_blank");
}

In ActionScript 2.0, you use the getURL() method to open a new browser window, as seen in the following example:

// ActionScript 2.0 (code on timeline)
/* Requires
 * - Button symbol on timeline 
 * - Button symbol on Stage with instance name "buttonSymbol"
 */
buttonSymbol.onRelease = function ():Void {
    getURL("http://www.adobe.com/", "_blank");
}

Or, in ActionScript 2.0 if you were placing code directly on instances on the Stage, as seen in the following example:

// ActionScript 2.0 (code directly on instance)
/* Requires
 * - Button symbol on Stage
 */
on (release) {
    getURL("http://www.adobe.com/", "_blank");
}
Tagged with:
 

12 Responses to Opening URLs in new browser windows using ActionScript 3.0 and ActionScript 2.0

  1. Daniel says:

    Hi peter, there is something special I have to do to open the url in a new tab?

  2. Peter deHaan says:

    Daniel,

    I typically specify the target attribute as “_blank”. I believe it may be up to the user’s browser settings to control whether that opens in a new tab or new browser window.

    Peter

  3. Peter deHaan says:

    For example, I searched around and found this link: “Internet Explorer 7: Open New Windows in Tabs in IE7″.

    Here’s how to have new windows and pop-ups to default to new tabs:

    1. Open IE7
    2. Click Tools
    3. Click Internet Options
    4. Click Settings
    5. Select Always open pop-ups in new tab
    6. Click OK until you are back in your browser
  4. Vijendra says:

    Hi Peter i want to open URL on enter frame … how is this done???

  5. Ronald says:

    So how do you in Actionscript 3.0 get a Flash document to open a like in the “_parent” window since I use frames? If anyone knows the answer, please send answer via e-mail. Much appreciated.

  6. Anonymous says:

    is it possible to interact with the opened window?

  7. thomas says:

    if you want a one line command do this:

    btn.addEventListener(MouseEvent.CLICK, function() {navigateToURL(new URLRequest(“http://www.adobe.com”, “_blank”))};

  8. Alex says:

    Hi Peter, I would like to know is there anyway to configure the new window attributes, like size, toolbars etc from within AS3

  9. Peter deHaan says:

    @Alex,

    I believe if you want to control toolbars and window size, you’d need to launch the window via JavaScript using the ExternalInterface class.

    Peter

  10. dengyasong says:

    Hi Peter, I would like to know is there anyway to configure the new window attributes, like size, toolbars etc from within AS3

  11. john says:

    how can i give the url in xml

  12. Kev Man says:

    Holy weak tutorial. You can get this with code snippets in CS5.

    Even more pathetic questions.

    How about this:

    How do you open up a sized window with actionScript 3?

Leave a Reply

Your email address will not be published.

You may use these HTML tags and attributes: <a href="" title=""> <abbr title=""> <acronym title=""> <b> <blockquote cite=""> <cite> <code> <del datetime=""> <em> <i> <q cite=""> <strike> <strong> <pre lang="" line="" escaped="" highlight="">

Spam Protection by WP-SpamFree