Creating and using variables

Variables are placeholders for values that you can assign later, when the Generator template is processed. You supply the values for the variables in data sources that you create.

Variables can hold positions where you later insert any string literal. This includes not just visible text but also text that has some function, such as with actions like Go To Label, or text that specifies the name of symbol to insert, or even text that provides a value of True or False to the Replace command's Replace Symbol property (effectively enabling or disabling the command).

You can define variables in the following places:

As text blocks on the Stage
As parameters to Generator objects
As parameters and arguments to Flash actions
As a frame label for use with actions in the main timeline and in child timelines


 
Defining variables

To define a variable, use the following syntax:

{GeneratorVariableName} 

The curly braces ({}) are required; they indicate a variable definition. Specify the name of the variable between the curly braces; the name can consist of any alphanumeric characters. Variable names are not case-sensitive.

As good development practice, try to give variables meaningful names that are unique within the template; this avoids confusion over ambiguous variable names. For example, {name} defines a variable called name, {address} creates a variable named address, and {greeting} defines a variable called greeting.

You can concatenate variables. For example, you can specify the following to display the full name:

{firstname} {lastname} 

See also Using data sources overview.

You can define the value for a variable using command-line parameters for offline processing, as URL parameters for online processing, or by placing them in an external data source. See Processing templates with Generator overview for more information.

If you specify a variable but do not define its value in a data source, it is usually left blank when Generator processes the template. If you've specified an undefined variable for an action, its declaration remains unchanged.


 
Using variables to dynamically replace text

You can use variables to dynamically replace text. If the parameter field requires specific values or accepts a limited range of values, be careful to supply a valid value for the variable in your data source.

To create variable text for dynamic replacement:

Use the text tool to create a text box in the movie. Type the variable name, enclosing it within braces, such as {variableName}. The variable name cannot contain spaces or any other nonalphanumeric characters.


 
Using variables as parameters to Generator objects and commands

You can specify variables for any Generator object or command where you can enter text. Simply type the variable in the parameter field.


 
Using variables as parameters for Flash actions

You can dynamically modify an action by specifying variables as parameters for any action field where you can enter text. You can even use variable expressions in the Expression Editor.

To use variables for action parameters:

1 Double-click a button or key frame in the timeline. Select the Action tab.
2 Insert an action for the button or keyframe.
3 Specify a variable for one of the action parameters using the {variableName} syntax.

Note: Some actions cannot be previewed with Flash; you need to preview them in a browser.

The following example shows how an action specified with a variable expression is replaced when Generator processes it.

Say you have the following data source, data.txt:

name, value
servervar, test
label, label1

Before the action is processed, it looks like this:

On (Release)
	Set Variable: "clientvar" = "{servervar}"
	If (clientvar eq "test")
		Trace ("servervar: {servervar}")
		Trace ("label: {label}")
		Goto and stop ("{label}")
	End If
End On

The following action represents the action after Generator rebuilds the action script using the data.txt data source:

On (Release)
	Set Variable: "clientvar" = "test"
	If ("test"  eq "test")
		Trace ("servervar: test")
		Trace ("label: label1")
		Goto and stop ("label1")
	End If
End On

When the button is pressed, the timeline goes to label1 and stops.