Flash CS3 Documentation |
|||
| ActionScript 2.0 Language Reference > ActionScript classes > TextField > styleSheet (TextField.styleSheet property) | |||
public styleSheet : StyleSheet
Attaches a style sheet to the text field. For information on creating style sheets, see the TextField.StyleSheet class entry.
The style sheet associated with a text field may be changed at any time. If the style sheet in use is changed, the text field is redrawn using the new style sheet. The style sheet may be set to null or undefined to remove the style sheet. If the style sheet in use is removed, the text field is redrawn without a style sheet.
Note: If the style sheet is removed, the contents of both TextField.text and TextField.htmlText change to incorporate the formatting previously applied by the style sheet. To preserve the original TextField.htmlText contents without the formatting, save the value in a variable before removing the style sheet.
Availability: ActionScript 1.0; Flash Player 7
The following example creates a new text field at runtime, called news_txt. Three buttons on the Stage, css1_btn, css2_btn and clearCss_btn, are used to change the style sheet that is applied to news_txt or to clear the style sheet from the text field. Add the following ActionScript to your FLA or AS file:
this.createTextField("news_txt", this.getNextHighestDepth(), 0, 0, 300, 200);
news_txt.wordWrap = true;
news_txt.multiline = true;
news_txt.html = true;
var newsText:String = "<p class='headline'>Description</p> Method; "
+ "starts loading the CSS file into styleSheet. The load operation is asynchronous; "
+ "use the <span class='bold'>TextField.StyleSheet.onLoad</span> "
+ "callback handler to determine when the file has finished loading. "
+ "<span class='important'>The CSS file must reside in exactly the same "
+ "domain as the SWF file that is loading it.</span> For more information about "
+ "restrictions on loading data across domains, see Flash Player security features.";
news_txt.htmlText = newsText;
css1_btn.onRelease = function() {
var styleObj:TextField.StyleSheet = new TextField.StyleSheet();
styleObj.onLoad = function(success:Boolean) {
if (success) {
news_txt.styleSheet = styleObj;
news_txt.htmlText = newsText;
}
};
styleObj.load("styles.css");
};
css2_btn.onRelease = function() {
var styleObj:TextField.StyleSheet = new TextField.StyleSheet();
styleObj.onLoad = function(success:Boolean) {
if (success) {
news_txt.styleSheet = styleObj;
news_txt.htmlText = newsText;
}
};
styleObj.load("styles2.css");
};
clearCss_btn.onRelease = function() {
news_txt.styleSheet = undefined;
news_txt.htmlText = newsText;
};
The following styles are applied to the text field. Save the following two CSS files in the same directory as the FLA or AS file you created previously.
Save this CSS file with the filename "styles.css"
.important {
color: #FF0000;
}
.bold {
font-weight: bold;
}
.headline {
color: #000000;
font-family: Arial,Helvetica,sans-serif;
font-size: 18px;
font-weight: bold;
display: block;
}
Save this CSS file with the filename "styles2.css"
.important {
color: #FF00FF;
}
.bold {
font-weight: bold;
}
.headline {
color: #00FF00;
font-family: Arial,Helvetica,sans-serif;
font-size: 18px;
font-weight: bold;
display: block;
}
If your SWF file includes a version 2 component, use the version 2 components' DepthManager class instead of the MovieClip.getNextHighestDepth() method, which is used in this example.
StyleSheet (TextField.StyleSheet)
Flash CS3
RSS feed | Send me an e-mail when comments are added to this page | Comment Report
Current page: http://livedocs.adobe.com/flash/9.0/main/00002240.html
Comments
No screen name said on Jul 23, 2007 at 1:19 AM :