Flash Script
none none none
none Summary
There are a few methods for creating Clickable links. In AS and AS2 it was very simple to just call getURL()
i.e.
getURL("http://domain.com/webpage.html","_blank");

However the easiest way to do so in AS3 is textfield.htmlText


htmlText

var link:TextField = new TextField();
link.htmlText = "<a href='http://somedomain.com'>SomeDomain</a>";
addChild(link);



setStyle

What about making the text blue AND underlined like a normal HTML link, how would one go about doing that.
Use a StyleSheet. (see code below)

var style:StyleSheet = new StyleSheet();
var link:TextField = new TextField();
style.setStyle("A",{textDecoration:"underline", color:"#0000FF", fontSize:"24", fontFamily:"Arial", fontWeight:"bold" });
link.styleSheet = style;
link.width = 280;
link.htmlText = "<a href='http://somedomain.com'>SomeDomain.com</a>";
addChild(link);



Alternatives

Here is an alternative way using navigate to URL, however if the flash file is running locally on the computer (and not hosted off the internet) One would need to get permission from the user (change the settings) to go to the internet. A minor point. Additionally one would need to change the mouse cursor when it rolls over the text to show that it is clickable.

public function Loader()
{
var link:TextField = new TextField();
link.text = "SomeDomain.com";
link.addEventListener(MouseEvent.CLICK, clickLink);
addChild(link);
}

function clickLink(e:MouseEvent)
{
navigateToURL(new URLRequest('http://somedomain.com'), '_blank');
}

none
none none none







History Licensing & Pricing Privacy Policy Contact Us
Frequently Asked Questions