Flash Templates Tutorials - Text Fields - Text fields and variable data
Text fields and variable data
To put data into the text field, you should only set the name and value of the variable, in case there are several variables, they are separated with & sign (ampersand).
In the file, necessary for work, we will specify any text as value of 'board' variable and will save it as text1.txt.
Now create a project containing text field and buttons.
Suppose that the text field is named "board", and when you click the first button, data from text1.txt file will be loaded into it, then the script for the first button will be:
Load Variables ( "text1.txt", 0)
As the names of the text field and of the variable are the same in the file, then as soon as data is loaded, they will be automatically assigned to this text field.
There is wide use of text downloading, which is not only data downloading but also creation of a variety of service applications. A striking example of combining text downloading with external clip is MbA module, another usage of it is the possibility of creating information panels with a daily updated content (you should only replace the text file).
As you know, when dealing with frames, we can set some specific names-tags using them in the future for jumping to various episodes: frames tags may serve not only for jumping, but also contain sub-programs at ActionScript, implementation of which may be fulfilled without going to this frame. Tags may (and should) be set for symbols instances from the library and for text editing fields.
How to do it:
Names of editing fields:
-- right-click on the field
-- select Properties
-- Text Field Properties window is opened:
-- enter the name in the field Variable
-- click OK
Why do you need it? Now, when the field has a name, we will be able to manage its content, to display the necessary text or calculated values.
Now let's practice our theory. Create a field in which the text will vary depending on the pressed button:
We need to create an editable text field with the name (e.g. field) on the stage and a button symbol in the library.
-- move the button to the scene and write a name on it
-- left double click on this button
-- select Action tab in the appeared window
-- Set Variable (setting the variable value)
-- enter the name of the filed at the Variable field (in our case it is field)
-- enter your name at the Value field
-- as a result the script should look like:
Set Variable: "field" = "David"
-- click OK
Now we have to see what we got. Launch the test preview by selecting Control / Test Movie, when pressing the button there will appear your name in the field. If you now create several buttons with different values, the field content will change depending on the pressed button. Please note that we take the button symbol from the library, and we set specific actions for its instances on the stage.
Variables can be of several types:
Number variables - contain numeric values, for example:
Set Variable: "year" = 2008
Set Variable: "temp" = 98.24
Symbol variables - contain symbols, text and enclosed in quotation marks
Set Variable: "name" = "Bill"
Set Variable: "dr" = "The best teacher"
Logical variables - can be only of two types True (1) or False (0)
Set Variable: "cool" = True
Set Variable: "cool" = 1
mean the same thing
Switching of variable type is produced by means of the button located on the right from the Value field: if the button says abc (String Literal), it would be a symbol variable, and if = sign (Expression), it is number variable then, but when choosing the type of variable you click on the symbol of the square with = sign (Expression Editor), then we arrive to the expression editor of ActionScript.