Blog
6

Regarding hyperlinks, there has been a significant change from Actionscript 2 to Actionscript 3.

In Actionscript 2, the following line of code would have sufficed to open a window in your default browser for this blog.

getURL("http://www.muktosoft.com/");

But in Actionscript 3, you need to instantiate an URLRequest then call navigateToURL to (:) navigate to your target url. See the code snippet bellow.

import flash.net.navigateToURL;

var req:URLRequest = new URLRequest("http://www.muktosoft.com");

navigateToURL(req);

Code explained :

First of all, import the required class from flash.net pacakge.

Now instantiate a URLRequest object with the target url provided in constructor, for our example the target is muktosoft.com.

Then call the public function navigateToURL (provided in flash.net package) to, offcourse, navigate to that url.

You can also control whether the new page should load in the same window or in a different one by providing a second parameter. For example, to open the target page in a new window, you have to put “_blank” as the second parameter.

navigateToURL(new URLRequest("http://www.muktosoft.com"), "_blank");

The possible values for the second parameter and their meanings are

The second parameter actually lets you tell on which browser window or HTML frame to display the document indicated by the request parameter. You can enter the name of a specific window or use one of the following values:

* “_self” specifies the current frame in the current window.
* “_blank” specifies a new window.
* “_parent” specifies the parent of the current frame.
* “_top” specifies the top-level frame in the current window.

Hope you find this useful.

6 Comments to “Hyperlink in actionscript 3”

Post comment

XHTML: You can use these tags: <a href="" title=""> <abbr title=""> <acronym title=""> <b> <blockquote cite=""> <cite> <code> <del datetime=""> <em> <i> <q cite=""> <strike> <strong>