Defining a Data Process with States Flash

When you manipulate text fields with internal Flash variables, then the data for the text fields is available for use immediately. Meaning, if you declare a variable and a value for that variable, that any text field can be given that value as well. When you want to load external data into a Flash movie, you need to create the appropriate steps, or “states,” in your movie to make sure that the data is available for use in the Flash movie. For example, say you want to retrieve a news article from a Web server, and the text for that article is contained within a variable named article_1. You can’t use or assign the value of article_1 to any other Flash element unless the article has fully downloaded to the Flash movie.

So, how do you know when data is available in a Flash movie? Any Flash movie that relies on data exchange between the Flash movie and the Web server should contain four separate steps, which are called states:

  • An input state to gather the information from the user or the movie
  • A send state in which a Flash action sends the data out of the movie
  • A wait state during which the data downloads to the movie
  • The output state in which the data can be used by the Flash movie in text fields and other ActionScript code

Input state
The first step for data exchange requires that you have something to send out of the Flash movie. The input can be a Flash form into which a user types text. The data could be environment variables, such as the time of the day or the Flash Player version. There could be various substeps in the input state, such as multiple forms or the completion of a quiz to calculate a test score that will be sent to the Web server.

Send state
Once the input data has been set in the Flash movie, you’re ready to send the data to another host, such as an application or script on your Web server. The following actions can be used to send data out of the Flash movie:

  • getURL
  • loadVariables
  • loadMovie

Of these actions, getURL is restricted to a one-way data path; that is, you can only send data out with getURL you cannot receive external data with getURL. getURL must target the sought URL to the current browser (or frame) or a new browser window. In many situations, you may only need to send data out of the Flash movie without needing to receive any further data. To send information with the user’s e-mail client, you can use a simple mailto URL in a getURL action on a Button instance:

In the preceding code block, the variables email, subject, and body are inserted into the getURL action. Note that you can automatically set subject and body text for the e-mail message as well! To add specific variables to a URL string, you should use the escape() function in ActionScript, which converts illegal URL characters such as spaces and ? into URL form-encoded text (for example, a space is converted into %20).

Wait state
If you are sending data from the Flash movie with loadVariables or loadMovie, then you need to know when the requested data is received. The most common way to detect the download state of data into the Flash movie is to use a terminal tag a name/value pair in the downloaded data that indicates the end of the data string. For example, if the textOutput variable that we used in the last section was converted to a name/value pair in a .TXT file (as URL form-encoded text), it would appear as the following (URL-converted characters are shown in bold, and the terminal tag is underlined):

textOutput=WANTED%3A%20Flash%20Input%20%26%20Output%0AA%20start%2Dup%20Dot%20com%20company%20is%20looking%20for%20a%20qualifie d%20web%20technology%20that%20will%20present%20text%20input%20a nd%20output%20to%20web%20visitors%20in%20a%20more%20compelling%20animated%20and%20visually%20stunning%20environment%20than%20t

At the end of this line of text (or at the very end of a long line of variables), we have inserted a terminal tag success=1. With this variable in place, we can set up a frame loop within our Flash movie to detect the existence (loading) of the terminal tag variable. After the terminal tag is loaded, the Flash movie will be directed to the appropriate output state.

All wait states should have a timeout condition: If the data fails to load within a certain time frame, then we will assume the Web server (or script) is not functioning correctly.If the timeout condition proves true, then the Flash movie will go to the appropriate output state. We create a wait state for our Flash form in the next section.

Output state
The final step in a data exchange is the actual display of any received data in the Flash movie. However, as indicated in the last state, there are two separate output states: a success display or an error display. If the data was properly received during the wait state, then the Flash movie will display the success output state. If the server failed to return any data to the Flash movie, then the movie will display an error output state, indicating that there was a problem with the server

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

Flash Topics