Flash CS3 文档 |
|||
| 学习 Adobe Flash 中的 ActionScript 2.0 > 使用文本和字符串 > 使用层叠样式表设置文本格式 > 在 XML 中使用样式的示例 | |||
在本部分中,您将创建一个具有 XML 格式文本的 FLA 文件。您将使用 ActionScript 创建一个样式表,而不是从 CSS 文件导入样式(如在 HTML 中使用样式的示例中所示)
var styles:TextField.StyleSheet = new TextField.StyleSheet();
styles.setStyle("mainBody", {
color:'#000000',
fontFamily:'Arial,Helvetica,sans-serif',
fontSize:'12',
display:'block'
});
styles.setStyle("title", {
color:'#000000',
fontFamily:'Arial,Helvetica,sans-serif',
fontSize:'18',
display:'block',
fontWeight:'bold'
});
styles.setStyle("byline", {
color:'#666600',
fontWeight:'bold',
fontStyle:'italic',
display:'inline'
});
styles.setStyle("a:link", {
color:'#FF0000'
});
styles.setStyle("a:hover", {
textDecoration:'underline'
});
此代码创建一个名为 styles 的新样式表对象,该对象通过使用 setStyle() 方法定义样式。这些样式与本章前面部分中在外部 CSS 文件中创建的样式完全匹配。
<story><title>Flash now has advanced anti-aliasing</title><mainBody><byline>San Francisco, CA</byline>--Adobe Inc. announced today a new version of Flash that features the new advanced anti-aliasing rendering technology. For more information, visit the <a href="http://www.adobe.com">Adobe Flash website</a></mainBody></story>
|
注意 |
|
如果要复制和粘贴此文本字符串,请确保删除所有可能已添加到该文本字符串中的换行符。从“动作”面板中的弹出菜单选择“隐藏字符”,查看并删除所有额外的换行符。 |
此代码将加载 story.xml 文档,将样式表对象分配到文本字段的 styleSheet 属性,并将 XML 文本分配到文本字段:
var my_xml:XML = new XML();
my_xml.ignoreWhite = true;
my_xml.onLoad = function(success:Boolean):Void {
if (success) {
news_txt.styleSheet = styles;
news_txt.text = my_xml;
} else {
trace("Error loading XML.");
}
};
my_xml.load("story.xml");
|
注意 |
|
在此 ActionScript 中,您将从外部文件加载 XML 数据。有关加载外部数据的信息,请参阅使用图像、声音和视频.。 |
Flash CS3
当前页: http://livedocs.adobe.com/flash/9.0_cn/main/00000919.html