TextField的htmlText属性,大家都使用过了。向其添加img标签后,你可以通过src属性添加图片,有趣的是你还可以添加swf影片。但,我刚才在这篇文章里发现更有趣的是,你还可以添加DisplayObject类及其子类!
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=’flash.text.TextField‘ width=’80′ height=’50′ />”;
var innerTxt:TextField = outerTxt.getImageReference(‘txt’) as TextField;
innerTxt.border = true;
innerTxt.text = “Inner TextField”;
}
}
}
如下图,可以在TextField里添加TextField:
通过这种方法向TextField添加DisplayObject时,有一个bug。当img标签前后都没有内容时这个bug就会出现:
package {
import flash.display.MovieClip;
import flash.text.TextField;
import flash.text.TextFormat;[SWF(width="300", height="200", backgroundColor="#FFFFFF")]
public class main extends MovieClip {
public function main() {
var txt:TextField = new TextField();
txt.border = true;
txt.x = 100;
txt.y = 50;
this.addChild(txt);txt.htmlText = “<img id=’img’ src=’flash.display.Sprite’ />”;
trace(txt.getImageReference(‘img’)); // nulltxt.htmlText = ” ” + “<img id=’img’ src=’flash.display.Sprite’ />”;
trace(txt.getImageReference(‘img’)); // [object Sprite]
}
}
}
原文:http://ticore.blogspot.com/2009/03/as3-textfieldhtmltext-trick-bug.html