Using Text Fields to Store and Display Data Flash

Before we can discuss sending and receiving data with Flash movies, you need to know the basic mechanisms of input and output. Most of the time, unless you are using Macromedia Generator templates, your data in Flash will be text based, which means that you will gather information from the user and display new and updated information with text. In Flash 5, Input Text fields gather data from the user, while Dynamic Text fields can be used to display live and updated text to the user.

Input Text fields
Input Text fields are created with the Text Tool. In the Text Options Panel, the top drop-down menu must be set to Input Text for the selected text field. An Input Text field has a variable name because it is a variable. The text that is typed inside of an Input Text field is the value of that variable. For example, if you create an Input Text field and assign it the variable name visitorInput, anything that is typed into that text field during runtime will become the value of visitorInput. To test this, let’s create a simple Input Text field.

  1. By using the Text Tool, create a text field on the Main Timeline of a Flash movie. Make the box long enough to hold 20 characters. You can type a temporary word or phrase into the text field, but delete these characters before proceeding to the next step.
  2. In the Text Options Panel, select Input Text in the top drop-down menu. In the Variable field, enter the text visitorInput. Check the Border/Bg option.
  3. Save your Flash movie as inputText.fla, and test the movie (Ctrl+Enter or Command+Enter). In the .SWF movie, click the text field and type your first name into the field.
  4. Choose Debug➪List Variables, and the visitorInput variable should display the value you typed in Step 3. In our example, we entered the name “Charlie.” Therefore, the Output window displays:
  5. If you change the text in the visitorInput text field, then the value will automatically update for the visitorInput variable. You need to choose List Variables from the Debug menu to see the updated value.Input Text fields not only accept input from the user, but they can also be set to an initial value or updated with a new value with ActionScript code. You can test this with the previous Flash movie example.
  6. If you are viewing the inputText.swf from Step 5, then close the .SWF movie to return to the Flash authoring environment. Create a new layer, and rename it Actions. Double-click the first frame of the Actions layer to open the Actions Panel. Add the following code to the Actions list:
  7. visitorInput = “enter your name here”;
  8. Save your Flash movie, and test it. You should see the text “enter your name here” in the visitorInput text field.As you can see, Input Text fields can accept text input from the user, just like an HTML form. Later, we use Input Text fields to create a fully functional Flash form that can send and receive information for a CGI (Common Gateway Interface) script.

Dynamic Text fields
If you want to display text information to people viewing Flash movies, you have two options: (a) create Static Text blocks whose contents can not be updated with ActionScript, or (b) create Dynamic Text fields that can be filled with internal Flash data or external text data.

Dynamic Text fields are also variables, just as Input Text fields. The only difference between Input and Dynamic Text fields is that you can type into Dynamic Text fields. Dynamic Text fields are most useful for display of text information that doesn’t need to be changed or updated by the user. Using Dynamic Text fields, you can display news articles that change on a daily (or hourly) basis, a player’s score during a Flash game, and the system time and date, just to name a few.

In the following steps, we create a Dynamic Text field that is updated with a Flash variable action. You can also load external variables for use in Dynamic Text fields, which we discuss in the next section. To insert text into a Dynamic Text field:

  1. By using the Text Tool, create a text field on the Main Timeline of a Flash movie. Make a block large enough to accommodate multiple lines of text.
  2. In the Text Options Panel, select Dynamic Text in the top drop-down menu.Select Multiline from the second drop-down menu. In the Variable field, enter the text textOutput. Check the Border/Bg and Word wrap options.
  3. Add a new layer, and name it Actions. Double-click the first keyframe of the Actions layer, and, in the Actions Panel, enter the following action (note that the ¬ indicates a continuation of the same line of code; do not insert this character in your actual code):
  4. In this code, we specify string values (denoted with quotes) for the actual text we want to insert into the textOutput Dynamic Text field variable. To insert a carriage return in the text, the newline constant is inserted between string values.

  5. Save the Flash movie as dynamicText_internal.fla.
  6. Test the movie (Ctrl+Enter or Command+Enter). The textOutput Dynamic Text field updates with the value assigned to the textOutput variable in ActionScript.You can also load text data into Input and Dynamic Text fields. This data can be returned from a simple text file (.TXT file) or from an application that resides on your Web server.


Face Book Twitter Google Plus Instagram Youtube Linkedin Myspace Pinterest Soundcloud Wikipedia

All rights reserved © 2018 Wisdom IT Services India Pvt. Ltd DMCA.com Protection Status

Flash Topics