I l @ ve RuBoard |
You can display text in Flash by using dynamic text fields. These are like the input text fields you learned about in Hour 9, "Getting Input From the User," but they cannot be used for direct user input. Instead, dynamic text fields can be used to display text with different styling and fonts. Dynamic Text OptionsYou create a dynamic text field by using the Text tool just like you would for an input text field. However, instead of choosing "Input Text", choose "Dynamic Text", as shown in Figure 10.1. Figure 10.1. The Properties panel for a dynamic text field.
The next step is to link this field to a variable, just like you do with input text. In Figure 10.1, you can see that I linked the field with a variable named " myText ". Now, whenever I change the variable " myText ", the dynamic text field will change to mirror it. You can also choose from a variety of other options. You can make it "Single", "Multiline", or "Multiline No Wrap" to reflect how you want the field to handle long lines. For a bit of information that should only take up one line, such as the score in an arcade game, you should use "Single". In most other cases, you should use "Mutliline". Across the top of the Properties panel, you will see some controls that let you set the font, size , and style of the text in the field. You can also click the Format button to change the indent, line spacing, and margins.
In the middle of the Properties panel, you will see three little buttons . The first, which looks like an "Ab" lets you decide whether the user can select the text in the field. Select this option if the user is supposed to be allowed to select and copy the text. In most cases, you will want it off. The next little button determines whether you can use HTML formatting in the field. We'll look at HTML formatting in the next section. The third button places a border around the field. The Character button in the Properties panel lets you decide which characters of the font will be saved with the movie when you publish it. Say that you have a dynamic text field and you want to put "Hello World." into it. First, you need to set the Var property in the panel to a variable name , such as myText . After that is done, don't worry about the field, just set the variable. myText = "Hello World."; It's that easy. But you can do much more with dynamic text fields. HTML FormattingThe easiest way to add formatting to dynamic text fields is to use HTML. First, you'll need to set the field to accept HTML. You do this by clicking the little Render Text as HTML button in the middle of the Properties panel. It looks like a "<>". When this is turned on, you can use a few select tags to change your text. Here is an example: myText = "This text is <B>bold</B>.<BR>"; myText += "This text is <I>italic</I>.<BR>"; myText += "This text is <U>underlined</U>.<BR>"; myText += "This text is <FONT COLOR='#FF0000'>red</FONT>.<BR>"; myText += "This text is <FONT FACE='Arial Black'>Arial Black</FONT>.<BR>"; myText += "This text is <FONT SIZE='24'>large</FONT>.<BR>"; myText += "This text is <A HREF='link.html'>linked</A>.<BR>"; This code builds a string of text that includes some HTML tags. Figure 10.2 shows the result. You can see this example in 10htmltext.fla. Figure 10.2. This styled text was created in ActionScript with HTML-like tags.
Notice that it is not a complete HTML page with a <BODY> tag or anything, so it is not true HTML. However, by using regular tags such as <B>, <I>, and <FONT>, it is easy to learn and remember what works. Here is a complete list of tags that work in Flash 6:
The hyperlink is the most functional of all the tags. On the one hand, it doesn't display blue and underlined like tags do in browsers, but it does work the same. If you click on a link, the page it refers to will load. If you want to color or style the text, you can apply those tags independently of the <A HREF> tag. TextFormat ObjectAnother way to set the font, size, and style of dynamic text is to use a TextFormat object. To do this, you create a variable and define it as an instance of TextFormat . Then, you can set various properties of this variable. In this example, the font is set to Arial Black, the size is set to 26, and the color is set to red. The dynamic text field has been named textInstance . We have never named a text field before, but you can see in Figure 10.1 where the name goes. myFormat = new TextFormat(); myFormat.font = "Arial Black"; myFormat.size = 36; myFormat.color = 0xFF0000; textInstance.setTextFormat(myFormat);
You can see this code in action in the example movie 10formattext.fla. The setTextFormat command can also accept a second and third parameter to tell it the first and last characters to apply the format to. You can use text format objects like style sheets in HTML. You can define several of them at the start of your movie and then apply those formats as you need them throughout the movie. |
I l @ ve RuBoard |