Skip to content
Dec 8 / Peter deHaan

Opening URLs in new browser windows using ActionScript 3.0 and ActionScript 2.0

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");
}

9 Comments

leave a comment
  1. Daniel / Dec 8 2008

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

  2. Peter deHaan / Dec 8 2008

    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 / Dec 8 2008

    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 / Dec 20 2008

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

  5. Ronald / Jul 9 2009

    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 / Sep 23 2009

    is it possible to interact with the opened window?

  7. thomas / Nov 14 2009

    if you want a one line command do this:

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

  8. Alex / Jan 12 2010

    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 / Feb 21 2010

    @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

Leave a Comment