【AS3代码】鼠标触发例子
package
{
import flash.display.Sprite;
import flash.events.TextEvent;
import flash.net.URLRequest;
import flash.net.navigateToURL;
import flash.text.TextField;
public class Main extends Sprite
{
private var txt:TextField;
public function Main():void
{
init();
}
private function init():void
{
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|dafeiji.swf'>这里</a></u>,则是加载一个动画。<br/>" +
"点击<u><a href='event:move|10'>这里</a></u>,则是将文本框移动10个像素。";
txt.addEventListener(TextEvent.LINK, clickLink);
}
//点击链接
private function clickLink(evt:TextEvent):void
{
trace(evt.text);
var cmdArray:Array = evt.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("调用了SWF:" + url);
}
private function movetxt(distance:Number):void
{
txt.x += distance;
}
}
}
{
import flash.display.Sprite;
import flash.events.TextEvent;
import flash.net.URLRequest;
import flash.net.navigateToURL;
import flash.text.TextField;
public class Main extends Sprite
{
private var txt:TextField;
public function Main():void
{
init();
}
private function init():void
{
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|dafeiji.swf'>这里</a></u>,则是加载一个动画。<br/>" +
"点击<u><a href='event:move|10'>这里</a></u>,则是将文本框移动10个像素。";
txt.addEventListener(TextEvent.LINK, clickLink);
}
//点击链接
private function clickLink(evt:TextEvent):void
{
trace(evt.text);
var cmdArray:Array = evt.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("调用了SWF:" + url);
}
private function movetxt(distance:Number):void
{
txt.x += distance;
}
}
}