Making Links

Here are two versions of the basic linking code in Actionscript 3/ AS3, (formerly known as getURL, from Actionscript 2).

Here’s the thorough one, which gives a message if there is an error:

//Don’t forget to name your button! And the function.
your_btn.addEventListener(MouseEvent.CLICK, functionName);

function functionName(e:MouseEvent):void {
var url:String = “http://www.aSiteYouWant.com”;
var request:URLRequest = new URLRequest(url);
try {
navigateToURL(request, ‘_blank’);
} catch (e:Error) {
trace(“Error occurred!”);
}
}

//Here’s the easy-peasy version with no error check:

your_btn.addEventListener(MouseEvent.CLICK, functionName);
function
functionName(e:MouseEvent):void {
var url:String = “http://www.aSiteYouWant.com”;
navigateToURL(new URLRequest(“http://www.example.com/”));
}