Hyperlink - html text in a textfield
The below outlines a simple method for building a link in a flash movie. The link can be used to call an external page or a file on the server. The point of the below example is to show a simple example. See other posts on this server about setting up the .fla, document class and .as file.
package {
import flash.display.Sprite;
import flash.events.TextEvent;
import flash.net.URLRequest;
import flash.text.TextField;
import flash.text.TextFormat;
import flash.external.ExternalInterface;//needed if using javascript (see below)
public class hyperlink extends Sprite
{
//---------------------------------------------------------------------------
public function hyperlink()
{
var myFormat:TextFormat = new TextFormat();
myFormat.font = "Arial";
myFormat.color = 0x0033FF;
myFormat.align = "left";
myFormat.underline = true;
myFormat.size = 12;
var link:TextField = new TextField();
link.htmlText = "Go to Test";
addEventListener(TextEvent.LINK, linkHandler);
link.setTextFormat(myFormat);
addChild(link);
}
//---------------------------------------------------------------------------
private function linkHandler(e:TextEvent):void
{
//testing
trace ("hyperlink to " + e.text);
//if hyperlink not working due to browser issue, the below (javascript) should work
//ExternalInterface.call("function(){location.href = '" + e.text + "';}")
}
//---------------------------------------------------------------------------
}
}
Copyright Gary Rosenzweig
