先说一下setTextFormat与defaultTextFormat的联系吧。 联系是二者的作用相同——都是将TextFormat对象应用于TextField对象,而TextFormat对象的作用是设置TextField对象的文本格式。 setTextFormat与defaultTextFormat的区别有两点: (1)最主要的区别是二者的性质不同:setTextFormat是方法而defaultTextFormat是属性。 (2)setTextFormat用于文本赋值之后,defaultTextFormat用于文本赋值之前。 下面通过一个实例(设置文本的格式)来区分一下吧。 var textfield:TextField=new TextField(); var textformat:TextFormat=new TextFormat(); textformat.color=0xff0000;//设置颜色 textformat.size=15;//设置文本大小 textformat.url="http://lgwindow.sdut.edu.cn";//设置连接 textformat.target="_blank"; textfield.text="山东理工大学新闻网"; textfield.autoSize=TextFieldAutoSize.LEFT; textfield.setTextFormat(textformat);//注意这里:setTextFormat为方法且用于textfield.text="山东理工大学新闻网";之后 addChild(textfield); textfield.x=textfield.y=150; 另外,如果用defaultTextFormat须这样写: var textfield:TextField=new TextField(); var textformat:TextFormat=new TextFormat(); textformat.color=0xff0000;//设置颜色 textformat.size=15;//设置文本大小 textformat.url="http://lgwindow.sdut.edu.cn";//设置连接 textformat.target="_blank"; textfield.defaultTextFormat=textformat;//注意这里:defaultTextFormat为属性且用于textfield.text="山东理工大学新闻网";之前 textfield.text="山东理工大学新闻网"; textfield.autoSize=TextFieldAutoSize.LEFT; addChild(textfield); textfield.x=textfield.y=150; |
setTextFormat和defaultTextFormat的用法
最新推荐文章于 2022-03-23 10:14:29 发布