Opening a URL in Action Script 3

Navigating to a URL in AS 2 was pretty straight forward.

getURL(“http://www.ryanwelcher.com”);

As with most things in AS3 that has changed a fair amount. It is no longer one line of code. I’ll show you everything and then walk you through it

var myLink:URLRequest = new URLRequest();

myLink.url = “http://www.ryanwelcher.com”;

navigateToURL(url);

Ok first things first.

var mylink:URLRequest = new URLRequest();

myLink.url = “http://www.ryanwelcher.com”;

We created an instance of the URLRequest class called myLink and set the url property to http://www.ryanwelcher.com

Last step

navigateToURL(myLink);

This line actually makes the call and opens the url in a browser window. You can pass a second argument for the window type so to have the link open in a new window the code would be

navigateToURL(myLink,”_blank”);

OPTION 2:

For all you kids that want to keep it on one line, this is the same code all condensed.

navigateToURL(new URLRequest(“http://www.ryanwelcher.com”),”_blank”);

Comments

Leave a Reply

Your email address will not be published. Required fields are marked *