Flash CS3 文档 |
|||
| 学习 Adobe Flash 中的 ActionScript 2.0 > 使用文本和字符串 > 使用层叠样式表设置文本格式 > 在 HTML 中使用样式的示例 | |||
本节介绍将样式用于 HTML 标签的示例。您可以创建对某些内置标签进行样式设置并定义某些样式类的样式表。然后,您可以将该样式表应用于包含 HTML 格式文本的 TextField 对象。
p {
color: #000000;
font-family: Arial,Helvetica,sans-serif;
font-size: 12px;
display: inline;
}
a:link {
color: #FF0000;
}
a:hover{
text-decoration: underline;
}
.headline {
color: #000000;
font-family: Arial,Helvetica,sans-serif;
font-size: 18px;
font-weight: bold;
display: block;
}
.byline {
color: #666600;
font-style: italic;
font-weight: bold;
display: inline;
}
此样式表定义两个内置 HTML 标签(<p> 和 <a>)的样式,这些样式将应用于这些标签的所有实例。它还定义两个样式类(.headline 和 .byline),样式类将应用于特定段落和文本范围。
在文件中添加下面的文本:
<p class='headline'>Flash adds advanced anti-aliasing rendering technology!</p><p><span class='byline'>San Francisco, CA</span>--Adobe Inc. announced today a new version of Flash that features a brand new font rendering technology called Advanced Anti-Aliasing, most excellent at rendering small text with incredible clarity and consistency across platforms. For more information, visit the <a href='http://www.adobe.com'>Adobe Flash web site.</a></p>
|
注意 |
|
如果要复制和粘贴此文本字符串,请确保删除所有可能已添加到该文本字符串中的换行符。 |
this.createTextField("news_txt", 99, 50, 50, 450, 300);
news_txt.border = true;
news_txt.html = true;
news_txt.multiline = true;
news_txt.wordWrap = true;
// 创建新样式表和 LoadVars 对象。
var myVars_lv:LoadVars = new LoadVars();
var styles:TextField.StyleSheet = new TextField.StyleSheet();
// 要加载的 CSS 和文本文件的位置。
var txt_url:String = "myText.htm";
var css_url:String = "html_styles.css";
// 定义 onLoad 处理函数并加载 CSS 文件。
styles.onLoad = function(success:Boolean):Void {
if (success) {
/* 如果样式表正确加载,
则将其分配到文本对象,
并将 HTML 文本分配给文本字段。 */
news_txt.styleSheet = styles;
} else {
trace("Unable to load CSS file.");
}
};
styles.load(css_url);
// 定义 onData 处理函数并加载要显示的文本。
myVars_lv.onData = function(src:String):Void {
if (src != undefined) {
news_txt.htmlText = src;
} else {
trace("Unable to load HTML file");
}
};
myVars_lv.load(txt_url);
|
注意 |
|
在这些 ActionScript 中,您将从一个外部文件加载文本。有关加载外部数据的信息,请参阅使用图像、声音和视频.。 |
Flash CS3
当前页: http://livedocs.adobe.com/flash/9.0_cn/main/00000917.html