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

by Peter deHaan on December 8, 2008

in General, migration

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

{ 8 comments… read them below or add one }

1 Daniel 12.08.08 at 5:51 pm

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

2 Peter deHaan 12.08.08 at 6:23 pm

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 12.08.08 at 6:38 pm

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 12.20.08 at 3:31 am

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

5 Ronald 07.09.09 at 9:02 pm

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 09.23.09 at 7:54 pm

is it possible to interact with the opened window?

7 thomas 11.14.09 at 6:11 pm

if you want a one line command do this:

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

8 Alex 01.12.10 at 10:26 am

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

Leave a Comment

You can 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="">

Previous post:

Next post: