• RSS
  • Facebook
  • Twitter
Comments

Postado por Fernando Schimit - Fox Creative



One of the bigger changes in Actionscript 3 is the way in which you call a link.
Flash 9 has been out for a few weeks now and Actionscript 3 is all the rage, but some things have started to confuse people. One of those is where getURL() disappeared to.
The old way (Actionscript 2) was to do it like this.
getURL("urltoload", "target");
In Actionscript 3 there is a little more to it.
var url:String = "http://site";
var request:URLRequest = new URLRequest(url);
try {
  navigateToURL(request, '_blank'); // second argument is target
} catch (e:Error) {
  trace("Error occurred!");
}
The more obvious difference is a call to the URLRequest class and pass that response into the navigateToURL() method.
Now if you wanted to rig this call to a button you would just set up a simple Event handler
movieClipName.addEventListener(MouseEvent.CLICK, callLink);
function callLink:void {
  var url:String = "http://site";
  var request:URLRequest = new URLRequest(url);
  try {
    navigateToURL(request, '_blank');
  } catch (e:Error) {
    trace("Error occurred!");
  }
}
Tip: If you wanted to use this example in Flex or an all Actionscript project you would want to include the necessary classes.

Categories:

Leave a Reply