Flex中如果想在图片上添加文字其实很容易,按照同样的道理。也可以在其它组件上添加文字,比如在一个canvas上添加文字。创建文本要使用到flash.text.Textfield类。代码如下
//创建TextField对象
var tf:TextField = new TextField();
tf.text = "ABC";
img.addChild(tf);
这样就可以在图片上看到文字了ABC了。
另外,通过TextFormat类可以格式化创建的文本,例如
var tf:TextField = new TextField();
tf.text = "ABC";
var format:TextFormat = new TextFormat();
format.size = 15
format.align = TextFormatAlign.RIGHT
format.color = 0xeeeeee;
tf.setTextFormat(format);
img.addChild(tf);
TextFormat和TextField 还有很多属性用来设置文本,可以参考相关资料。
<script type="text/javascript" id="wumiiRelatedItems"> </script>