gavin sim logo
 

Week 1

Week 2

Week 3

Week 4

Week 5

Week 6

Week 7

Week 8

Week 9

Teaching > ActionScript

CSS and Flash

The open notepad and type the following code and save it as my_style.css.

 p {
font-family: Times New Roman, Times, _serif;
font-size: 44;
font-Style: italic;
margin-left: 10;
}

The code defines the styles for the p tag within the Flash movie. The CSS defines the font type, font size and italics of the text in the flash movie. Ensure the file is in the same director as your Flash movie.

 

Part 2

With in Flash create a dynamic text box on the screen and give it the instance name of my_txt. Then create a new layer and name the layer actions and input the following code:

var style:StyleSheet = new StyleSheet();

This simply creates a new style sheet variable which will store the style sheet data. You will then need to create some code to load in the CSS file you have created. This is similar to all the other examples of loading content. The function that you need to call when the file is loaded is cssLoaded.

 

Then add the following code:

function cssLoaded (event:Event):void{
 style.parseCSS(CSSLoader.data);
 myText.styleSheet = style;
 myText.htmlText = "<html> <body><p> hello!!</p></body></html>";
 }

Ehen the file is loaded the data is parsed and stored in the style variable. This varaible is then attached to the dynamic text box that you created. Th enext line sets the text as HTML text within flash therefore the stylesheet will be applied.

Save your file and test the movie.