package {
import flash.display.Sprite;
import flash.events.TextEvent;
import flash.net.URLRequest;
import flash.text.TextField;
import flash.net.navigateToURL;
public class testHtmlLink extends Sprite
{
private var txt:TextField;
public function testHtmlLink()
{
txt = new TextField();
txt.width = 300;
txt.wordWrap = true;
this.addChild(txt);
txt.htmlText = "单击<u><a href='event:geturl|http://www.baidu.com/|_blank'>这儿</a></u>在"+
"新窗口打开一个到www.baidu.com的链接。<br/>"+
"单击<u><a href='event:load|a.swf'>这儿</a></u>则是在flash中加载动画。<br/>"+
"单击<u><a href='event:move|10'>这儿</a>,</u>则是将文本框移动10个像素。";
txt.addEventListener(TextEvent.LINK,clickLink);
}
private function clickLink(event:TextEvent):void
{
trace(event.text);
var cmdArray:Array = event.text.split("|");
switch(cmdArray[0])
{
case "geturl":
geturl(cmdArray[1],cmdArray[2]);
break;
case "load":
loadswf(cmdArray[1]);
break;
case "move":
movetxt(cmdArray[1]);
break;
default:
trace(cmdArray);
}
}
private function geturl(url:String,target:String):void
{
var tmpRequest:URLRequest = new URLRequest(url);
navigateToURL(tmpRequest,target);
}
private function loadswf(url:String):void
{
trace("load a swf from: "+ url);
}
private function movetxt(distance:Number):void
{
txt.x += distance;
}
}
}