Flash: Using CSS
April 29th, 2005 by LuisJust a very basic sample of how to use CSS in flash
css file (sample.css):
CSS:
- p {
- color: #000000;
- font-family: arial,sans-serif;
- font-size: 12px;
- display: inline;
- }
- a:link {
- color: #6B8CC9;
- text-decoration: none;
- }
- a:hover{
- color: #6B8CC9;
- text-decoration: underline;
- }
- .headline {
- color: #000000;
- font-family: arial,sans-serif;
- font-size: 20px;
- font-weight: bold;
- display: block;
- }
Flash code:
Actionscript:
- var myCSS = new TextField.StyleSheet();
- var cssURL = "sample.css";
- myText = "<p class='headline'>Lorem ipsum</p>";
- myText += "<a href='http://www.lipsum.com/'>Lorem ipsum</a>";
- myText += " dolor sit amet, consectetuer adipiscing elit.";
- myText += "Cras molestie tempor odio. Cras facilisis.";
- myText += " Vivamus est mi, fringilla nec...";
- myCSS.load(cssURL);
- myCSS.onLoad = function(success) {
- if (success) {
- myTextField.styleSheet = myCSS;
- myTextField.text = myText;
- }
- };
Sample swf:
[flash]http://www.blog.lessrain.com/wp-content/upload/sample.swf,400,122[/flash]


June 13th, 2005 at 1:25 pm
[…] : Embed SWF Flash: Extending CSS capability Following up our post Flash: Using CSS I found out that Flash internally converts every CSS-class into a TextFormat Object. That’s w […]
December 6th, 2005 at 9:08 pm
send me code.I am student
December 7th, 2005 at 10:51 am
The code is here already
August 30th, 2006 at 3:17 am
I tried this but it does not work in Flash MX 2004
September 30th, 2006 at 3:01 am
[…] extField.styleSheet = myCSS; myTextField.text = myText; } }; This info comes courtesy of: Lessrain Blog Actionscript.org Kirupa.com Update - 11/05/2006 Okay, here’s the code in action (with a f […]