使用 HTML 格式文本必需的属性和语法

若要在文本字段中使用 HTML,您必须在“属性”检查器中或使用 ActionScript 来设置该文本字段的多个属性:

例如,下面的代码为名为 headline_txt 的文本字段启用 HTML 格式设置,然后将一些 HTML 分配到该文本字段:

this.createTextField("headline_txt", 1, 10, 10, 500, 300);
headline_txt.html = true;
headline_txt.wordWrap = true;
headline_txt.multiline = true;
headline_txt.htmlText = "<font face='Times New Roman' size='25'>This is how you assign HTML text to a text field.</font><br>It's very useful.</br>";

若要正确地呈现 HTML,必须使用正确的语法。HTML 标签的属性必须括在双引号 (") 或单引号 (') 中。不带引号的属性值可能产生无法预料的结果,例如不正确的文本呈现。例如,Flash Player 无法 正确呈现下面的 HTML 代码片段,因为分配给 align 属性的值 (left) 未包含在引号中:

this.createTextField("myField_txt", 10, 10, 10, 400, 200);
myField_txt.html = true;
myField_txt.htmlText = "<p align=left>This is left-aligned text</p>";

如果将属性值包含在双引号中,则必须对引号进行转义 处理 (\")。采用以下两种方法之一均可:

myField_txt.htmlText = "<p align='left'>This uses single quotes</p>";
myField_txt.htmlText = "<p align=\"left\">This uses escaped double quotes</p>";
myField_txt.htmlText = '<p align="left">This uses outer single quotes</p>';
myField_txt.htmlText = '<p align=\'left\'>This uses escaped single quotes</p>';

如果从外部文件加载文本,则无需对双引号进行转义处理;只有在 ActionScript 中分配文本字符串时才需执行此操作。


Flash CS3

 

评论添加到页面后给我发送电子邮件 | 评论报告

当前页: http://livedocs.adobe.com/flash/9.0_cn/main/00000921.html