DefaultTextFormat VS调用setTextFormatDefaultTextFormat、VS、setTextFormat

由网友(大姨妈红遍了整个床)分享简介:这里有2 code块。 VAR myTextField的:文本字段=新的TextField();VAR myTextFormat:的TextFormat =新的TextFormat();的addChild(myTextField的);myTextFormat.font =宋体;myTextFormat.size =...

这里有2 code块。

  VAR myTextField的:文本字段=新的TextField();
VAR myTextFormat:的TextFormat =新的TextFormat();

的addChild(myTextField的);

myTextFormat.font =宋体;
myTextFormat.size = 15;
myTextFormat.color = 0x0000FF;

myTextField.text =一些文本;
** myTextField.setTextFormat(myTextFormat)**
 

VS

  VAR myTextField的:文本字段=新的TextField();
VAR myTextFormat:的TextFormat =新的TextFormat();

的addChild(myTextField的);

myTextFormat.font =宋体;
myTextFormat.size = 15;
myTextFormat.color = 0x0000FF;

** myTextField.defaultTextFormat = myTextFormat **
 

那么,什么是之间的区别 调用setTextFormat()和defaultTextFormat?为什么两种不同的方式(一个由法属性另一人)做的事情。

测试与一些code:

  VAR my_txt发生:文本字段=新的TextField();
    my_txt.type =为TextFieldType.INPUT
     VAR my_fmt:的TextFormat =新的TextFormat();
     my_fmt.color =为0xFF0000;

     my_txt.text =这是调用setTextFormat与范围;
     my_txt.setTextFormat(my_fmt,0,3);

    // my_txt.text =这是调用setTextFormat无范围;
    // my_txt.setTextFormat(my_fmt);

    // my_txt.defaultTextFormat = my_fmt;
    // my_txt.text =这是默认的文本格式;

    的addChild(my_txt发生);
 
起点下载站 每日更新一键转帖论坛UBB代码 代码转换器

诉 解决方案

调用setTextFormat允许您更改格式上的文字部分。查看调用setTextFormat的另外两个参数。当您设置defaultTextFormat它是适用于所有添加的文本字段的文本。

更多信息:

http://help.adobe.com/en_US/FlashPlatform/reference/actionscript/3/flash/text/TextField.html#defaultTextFormat

http://help.adobe.com/en_US/FlashPlatform/reference/actionscript/3/flash/text/TextField.html#setTextFormat

编辑: 同时调用setTextFormat不后您设置的格式,插入文本工作。 Adobe表示 任何文字手动插入的用户,或者换成replaceSelectedText()方法,接收默认的文本格式设置为新的文本,而不是为文本插入点指定的格式要设置默认格式为新文本,请使用defaultTextFormat 。

here are 2 code blocks.

var myTextField:TextField = new TextField();
var myTextFormat:TextFormat = new TextFormat();

addChild(myTextField);

myTextFormat.font = "Arial";
myTextFormat.size = 15;
myTextFormat.color = 0x0000FF;

myTextField.text = "some text";
**myTextField.setTextFormat(myTextFormat);**

VS

var myTextField:TextField = new TextField();
var myTextFormat:TextFormat = new TextFormat();

addChild(myTextField);

myTextFormat.font = "Arial";
myTextFormat.size = 15;
myTextFormat.color = 0x0000FF;

**myTextField.defaultTextFormat = myTextFormat;**

So , What's the difference between setTextFormat() and defaultTextFormat ? Why two different ways ( one by property another by method) to do things.

Tested with some more code :

var my_txt:TextField =new TextField();
    my_txt.type = TextFieldType.INPUT
     var my_fmt:TextFormat = new TextFormat();
     my_fmt.color = 0xFF0000;

     my_txt.text = "this is for setTextFormat with range";
     my_txt.setTextFormat(my_fmt,0,3);

    // my_txt.text = "this is for setTextFormat without range";
    // my_txt.setTextFormat(my_fmt);

    // my_txt.defaultTextFormat = my_fmt;
    // my_txt.text = "this is for default text format";

    addChild(my_txt);

V.

解决方案

setTextFormat allows you to change the formatting on parts of the text. Check out the other two parameters of setTextFormat. When you set defaultTextFormat it is applied to all the text that you add to the TextField.

More info :

http://help.adobe.com/en_US/FlashPlatform/reference/actionscript/3/flash/text/TextField.html#defaultTextFormat

http://help.adobe.com/en_US/FlashPlatform/reference/actionscript/3/flash/text/TextField.html#setTextFormat

Edit : Also setTextFormat doesn't work on text that is inserted after you set the format. Adobe says "Any text inserted manually by the user, or replaced by the replaceSelectedText() method, receives the default text field formatting for new text, and not the formatting specified for the text insertion point. To set the default formatting for new text, use defaultTextFormat."

阅读全文

相关推荐

最新文章