a标签侦听事件:
textFiled.htmlText = "<a href='event:typetext'>con</a>";
textFiled.addEventListener(TextEvent.LINK,linkhandle);
function linkhandle(event:TextEvent):void{
trace(event.type); //link
trace(event.text); //typetext
trace(event.target.text) ; //con
}
至于img中src和url的导入还有用embed绑定的图片的绑定网上文章很多,也不多述了。讨论一下通过src指定Linkage Identifier的方式,这里也有一篇文章:http://www.6dn.cn/blog/article.asp?id=119 ,项目需要,我不希望再给每个img赋予 id并进行处理,所以尝试了一下:
package {
import flash.display.MovieClip;
import flash.text.TextField;
[SWF(width="300", height="200", backgroundColor="#FFFFFF")]
public class main extends MovieClip {
public function main() {
var outerTxt:TextField = new TextField();
outerTxt.border = true;
outerTxt.x = 100;
outerTxt.y = 50;
this.addChild(outerTxt);
outerTxt.htmlText = "Outer TextField<img id='txt' src='http://blog.163.com/zsmhunter@126/blog/TestSprite' width='80' height='50' />";
}
}
}
{
import flash.display.Sprite;
import flash.text.TextField;
public class TestSprite extends Sprite
{
public function TestSprite()
{
var innerTxt:TextField = new TextField();
innerTxt.border = true;
innerTxt.text = "Inner TextField";
this.addChild(innerTxt);
}
}
}
效果如图:
从出来的效果可以看到,textfiled默认大小是100,100;img标签中设定了width = 80, height = 50,所以直接修改了sprite的缩放来实现,于是乎再做如下修改:
package
{
import flash.text.TextField;
public class TestSprite extends TextField
{
public function TestSprite()
{
this.border = true;
this.text = "Inner TextField";
}
}
}
效果如图: