代碼如下,主要是注意html標籤的寫法。
import flash.text.TextField;
import flash.events.TextEvent;
import flash.text.TextFieldAutoSize;
var txt:TextField = new TextField();
this.addChild(txt);
txt.htmlText = "<font color='#ff0000'><a href='event:關於本站'>關於本站</a></font> | <a href='event:廣告服務'>廣告服務</a>";
txt.autoSize = TextFieldAutoSize.LEFT;
txt.addEventListener(TextEvent.LINK,textOnClick);
function textOnClick($evt:TextEvent):void
{
if($evt.text == "關於本站")
{
trace("你點擊的是:關於本站");
}
else if($evt.text == "廣告服務")
{
trace("你點擊的是:廣告服務");
}
}