Flash CS3 Documentation |
|||
| Learning ActionScript 2.0 in Adobe Flash > Working with Text and Strings > Formatting text with Cascading Style Sheet styles > An example of using styles with HTML | |||
This section presents an example of using styles with HTML tags. You can create a style sheet that styles some built-in tags and defines some style classes. Then, you can apply that style sheet to a TextField object that contains HTML-formatted text.
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;
}
This style sheet defines styles for two built-in HTML tags (<p> and <a>) that will be applied to all instances of those tags. It also defines two style classes (.headline and .byline) that will be applied to specific paragraphs and text spans.
Add the following text to the file:
<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>
|
NOTE |
|
If you copy and paste this text string, make sure that you remove any line breaks that might have been added to the text string. |
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;
// Create a new style sheet and LoadVars object.
var myVars_lv:LoadVars = new LoadVars();
var styles:TextField.StyleSheet = new TextField.StyleSheet();
// Location of CSS and text files to load.
var txt_url:String = "myText.htm";
var css_url:String = "html_styles.css";
// Define onLoad handler and Load CSS file.
styles.onLoad = function(success:Boolean):Void {
if (success) {
/* If the style sheet loaded without error,
then assign it to the text object,
and assign the HTML text to the text field. */
news_txt.styleSheet = styles;
} else {
trace("Unable to load CSS file.");
}
};
styles.load(css_url);
// Define onData handler and load text to display.
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);
|
NOTE |
|
In this ActionScript, you are loading the text from an external file. For information on loading external data, see Working with Images, Sound, and Video. |
Flash CS3
Send me an e-mail when comments are added to this page | Comment Report
Current page: http://livedocs.adobe.com/flash/9.0/main/00000917.html