gavin sim logo
 

Week 1

Week 2

Week 3

Week 4

Week 5

Week 6

Week 7

Week 8

Week 9

Teaching > ActionScript

Dynamic Text

Create a new flash document.

Open the actions panel and type:

var myLink:TextField = new TextField();
myLink.htmlText = "Visit <A HREF='http:gavinsim.com/actionscript'> Gavin's actionscript page</A>";
addChild(myLink);

This will create a new textField variable called myLink and then using the .htmlText property a link is attached to the text. The final lines adds the textField to the stage.

Control / Test Movie

 

Excercise

Make the width of the text area to 350 and poistion it on the stage at 300 and 250.

 

Part 2 CSS

Now we will modify the code to attach a style sheet to it, above the existing code add:

var myStyleSheet:StyleSheet = new StyleSheet();
myStyleSheet.setStyle("A",{textDecoration: "underline", color: "#0000FF"});

The first line creates a new stylesheet variable and the next line sets its properties in this case for the A tag.

Note It is also possible to use external style sheets and then apply this to the text.

In order to apply the stylesheet to the myLink text we need to assign the stylesheet to the text. Underneath the line where you created the myLink variable add the following code:

myLink.styleSheet = myStyleSheet;
Control / Test Movie and you will see the style sheet applied to the link text.