AS3: what to do without getURL()?
In previous versions of AS, just a few lines of simple codes will allow you to click on a button and go to another website. In AS3, however, getURL() is replaced. You have to do the following:
Actionscript:
-
import flash.net.*;
-
import flash.events.*;
-
//
-
btn.addEventListener(MouseEvent.CLICK,onClick);
-
var ur:URLRequest = new URLRequest("http://www.adobe.com");
-
//
-
function onClick(e:Event):void{
-
navigateToURL(ur, "_blank");
-
}
btn is a movie clip on stage. When someone click on it, it will trigger the onClick() function and bring the user to adobe web.
Then, you have to declare the url with the URLRequest object. Last but not the least, we have to code the onClick() function.
getURL() is replaced by navigateToURL(), which belongs to flash.net. The syntax is:
Actionscript:
-
public function navigateToURL(request:URLRequest, window:String = null):void
The 1st parameter is the URLRequest object that contains the target url. The 2nd parameter defines whether a new window will pop up or open the website in the current window.