In This tutorial I will show you the alternative for the good old getURL() function that was included in AS2 and has undergone major changes in AS3 to an extent that it is no more functional in AS3.
In the old days(AS2), we used to do it like this:
getURL("link", "target");
In AS3 it is much more different here is how it is done:
var myUrl:String = "http://theSiteYouWantToLoad"; var myRequest:URLRequest = new URLRequest(myUrl); try { navigateToURL(myRequest, 'target'); // second argument is target } catch (e:Error) { trace("An Error Occurred while trying to open the link!"); }
Here is an explanation for the process, first of all you will have to initialize a variable with type string in which you store the link to the site. Next you will have to create an instance of a URLRequest and submit your URL into it as an argument. Next you will be able to open the Url through the method: navigateToURL() instead of getURL(). In this case you will have to supply your URL request(myRequest) as an argument along with the target of your link e.g. _blank
You have to make sure to include your navigateToURL() statement in try...catch block in order to catch any exception that may result during execution as shown in the code above.
Beginners may find the AS3 way complex but actually it is much better in terms of flexibility, security and error handling. I hope this simple tutorial has helped, good luck in you AS3 scripting and have a good day
