Declaring Variables in Flash Flash

There are several ways to establish, or declare, variables in a Flash movie. You can create them directly with ActionScript (or with Text Fields, as seen in the last section), load them from a text file or CGI (Common Gateway Interface) script, or include them in HTML tags.

Using actions to define variables
The most common way to create a variable is to type the variable’s name and value in the Actions list of the Actions Panel, on a specific timeline’s keyframe, accessed in the Frame Properties or Instance Properties dialog. Most basic variables will have values that are string literals. If you are using Normal Mode in the Actions Panel, then a var action has one option: variables. Note that the var action is used for local variables that only exist for the duration of a function execution.

Loading variables from a predefined source
You can also establish variables by loading them from an external source, such as a text file located on your Web server or even through a database query. By using the loadVariables action, you can load variables in this fashion. There are three primary options for the loadVariables action: URL, Location, and Variables .

The options of the loadVariables action

The options of the loadVariables action

URL specifies the source of the variables to be loaded. This can be a relative link to the variable source (you don’t need to enter the full path of the resource). You can specify whether this URL value is a literal value or an expression that uses a variable or a combination of variables (serverURL + scriptPath + scriptApp).

The Location option determines where the variables are to be loaded. You can send the name/value pairs to a level or a timeline target. If you want the variables to be available on the Main Timeline, use _root or _level0. You can also specify a Movie Clip target using a relative or absolute address. To load to the current Movie Clip (the one initiating the loadVariables action), use the target this. The last option is Variables, and this drop-down menu specifies whether you are sending and loading (in other words, receiving) variables. If you want to load variables from a static source, like a text file, you should choose Don’t Send. If you are sending a query to a database-driven engine, then you will need to choose either GET or POST.

Note that the use of loadVariables in GET or POST method means that you are sending variables declared on the active timeline to the specified URL, which, in turn, will send name/value pairs back to the Flash movie. The formatting of name/value pairs is standard URL-encoded text. If you want to encode name/values in a text file (or a database), you need to use the following format:

variable=value&variable=value...

Basically, in URL-encoded text, name/value pairs are joined by an ampersand (&). To join multiple terms in a value, use the plus (+) symbol, as in:

name1=Joe+Smith&name2=Susan+Deboury

Sending variables to URLs
You can also send variables to a URL by using the getURL action. Any name/value pairs that are declared on the active timeline will be sent along with the getURL action, if a variable send method is defined (GET or POST). Note that getURL is only used to send variables out of a Flash movie—it will not retrieve or load any subsequent name/value pairs. If you use a getURL action on a Movie Clip timeline as follows:

The output of the form.cgi script would be opened in a new browser window

(“_blank”).

Establishing variables with HTML
You can also send variables to Flash movies in the <EMBED> and <OBJECT> tags that call the Flash movie. In the SRC attribute of <EMBED> or the PARAM NAME=movie subtag of the <OBJECT> tag, attach the name/value pairs to the end of the Flash movie filename, separated by a question mark (?).

<OBJECT...><PARAM NAME=movie VALUE=”flash.swf?name=Rob”><EMBED SRC=”flash.swf?name=Rob”>


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