|
It's hard to create an app of any real substance these days without creating hyperlinks that load a URL when the user clicks on them. These could just be links that open a new web page, launch your e-mail app for sending an e-mail, or any other type of crazy thing you would want to do with URLs. In this article, I will briefly show you how to use ActionScript 3.0 (AS3) to create a hyperlink - similar to the example you see below: Click on the "Send E-Mail" or "Launch Web Page" link to either see your e-mail application launch or your browser taking you to the kirupa.com home page. Let's look at how this works. Introducing URLRequest
There are only two parts to creating a hyperlink. The first part is declaring and initializing your URLRequest object:
As part of your URLRequest constructor, you can specify the link you would like to see opened. Once you your URLRequest object, referenced in this case by homeLink, you are good to go. You simply have to invoke the navigateToURL method and pass in your URLRequest object as an argument:
The combination of the navigateToURL method and your URLRequest object is all you really need to create a hyperlink, and the next section will look into the above two lines of code in the context of a more realistic application. More Realistic Example + Window
Targets The following is the code I used in the example animation you saw above:
Most of the code you see above should be very familiar to you. I am simply setting up events and event handlers so that when one of my buttons get clicked, something happens. What is different is the following line:
Notice that the navigateToURL method I showed you earlier takes in another argument besides the URLRequest object. It takes the window target as an argument. In this case, my argument is _self. The range of target values you can specify are:
Conclusion
Just a final word before we wrap up. What you've seen here is freshly baked content without added preservatives, artificial intelligence, ads, and algorithm-driven doodads. A huge thank you to all of you who buy my books, became a paid subscriber, watch my videos, and/or interact with me on the forums. Your support keeps this site going! 😇
:: Copyright KIRUPA 2026 //-- |