Dynamic Text Fields: More Power!
Overview
Often, when you have large amounts of text to display, you'll want to use a scrolling text box. That means you'll have to make the text field "dynamic". That, in turn, means you can't do much formatting of the text field within Flash.
Fortunately, Flash can interpret HTML tags. You can use these to create pre-formatted text files and include hyperlinks. This technique is best achieved by creating and then importing a separate text file. An extra benefit to this method is that the text file can be edited by someone who doesn't have Flash -- which makes it much easier to share the workload across a project team.
Unfortunately, hyperlink text doesn't automatically "look" like a hyperlink when imported. Further, some special characters, such as the Trademark Symbol, fail to display properly when imported. The problem, then, is how to format the text file, get that text file into Flash, and then display it properly.
First Steps
First, create your text file in a plain-text editor such as Notepad. (I'd suggest that you avoid using Microsoft Word® because it will convert special characters to plain text when you save the plain-text file.)
Before the first word of your text, type "myText=", and then put an ampersand (&) at the very end of the text. This process creates a variable, or container, for your text and also tells Flash where that variable's content ends.
Delete extra spaces between paragraphs. Flash will add space back in just like HTML default paragraph style does. Save the file as "textfile.txt".
Now, do you know enough HTML to tag your text? If so, skip to ActionScripting. If not, please read the next section.
Tag it
Creating a bulleted list
For a bullet list:
- Just before the list begins, put the tag for an Unordered List:
- Put the tag for List Item before each bullet point:
- Put the tag to end a List Item at the end of each bullet point:
- Put the tag to end your Unordered List after the last end-List-Item tag:
- Delete all paragraph spaces in your list. The HTML tags will create a new line for each item.
I've just done the exact thing here, in fact.
Including a hyperlink
Use the typical hyperlink tag for your desired link.
EXCEPT, Flash will NOT make the words "click here" LOOK like a link, so add some more HTML formatting to make the words blue and underlined:
You can use several other HTML tags, which are covered in a tutorial by Alan Wisternoff: HTML use in Dynamic Textboxes
Use the Windows® Character Map (or type the character code) to insert special characters. Let's use the Trademark Symbol (™) as an example. To create that symbol using the character code, type
Once you've formatted your document, you still need to tell Flash what to expect and what to do with it. So, read on...
ActionScripting
An important point relating to scrolling text fields
The scrollbar utilizes the field's instance name. If you fail to give your field an instance name, Flash will automatically assign one such as InstanceName_0. That works, but it can be awkward. So, using the Properties panel, change the instance name to "Field1".
Finally: Tell Flash what to do
In the first frame of your movie, place the following script:
//tell Flash to display special characters
System.useCodepage=true;
// set the text field to use HTML tags
Field1.html=true;
//create a new "LoadVars" object
myLoadVar = new LoadVars ();
//load the contents of the text file into the LoadVars object
myLoadVar.load("textfile.txt");
//check to see if the loading is completed and, if so, put the contents in the text field
myLoadVar.onLoad = function (success){
if (success == true) {
Field1.htmlText=myLoadVar.myText;
}
}
Let Me Sum Up
By combining Flash features with HTML tags, we've made it possible to use dynamic text fields in a much more powerful way. This tutorial has explained some of these techniques... I hope it's a launch pad for some creative ideas of your own!
| » Level Intermediate |
Added: : 2003-12-16 Rating: 6.78 Votes: 138 Hits: 1564 |
| » Author |
| I work in the training section of a non-profit agency. Being the only Flash user in my organization, I've used the techniques in this tutorial to avoid having to make constant edits to our training materials! |
| » Download |
| Download the files used in this tutorial. |
| Download (0 kb) |
discuss this topic to forum
