捕获超文本链接的信息

package 

{

	import flash.display.Sprite;

	import flash.text.TextField;

	import flash.events.TextEvent;

	import flash.net.URLRequest;

	import flash.net.navigateToURL;



	public class SampleTextLink extends Sprite

	{



		private var txt:TextField;



		public function SampleTextLink()

		{

			txt = new TextField  ;

			txt.width = 300;

			//自动换行

			txt.wordWrap = true;

			//设置不可选

			txt.selectable=false;

			addChild(txt);

			txt.htmlText=

			"单击<u><a href='event:geturl|http://www.baidu.com'>这儿</a></u>在"+

			"新窗口打开一个到www.baidu.com链接\n"+

			"单击<u><a href='event:move|10'>这儿</a></u>则是将文本框移动10个像素.";

			txt.addEventListener(TextEvent.LINK,clickLink);

		}



		private function clickLink(e:TextEvent):void

		{

			trace(e.text);

			var arr:Array=e.text.split("|");

			switch(arr[0])

			{

				case "geturl":

					geturl(arr[1]);

				case "move":

					move(arr[1]);

			}

		}

		

		private function geturl(url:String):void

		{

			var request:URLRequest=new URLRequest(url);

			navigateToURL(request,"_blank");

		}

		

		private function move(num:Number):void

		{

			txt.x+=num;

		}

	}



}

你可能感兴趣的:(链接)