Home arrow Flash arrow Page 5 - Building Web Forms In Flash

Coming Back For More - Flash

In addition to building animation clips on the fly, Flash canalso be used to build simple Web forms to collect user data on your Website. This article demonstrates the process, showing you how to buildsimple Flash forms and link them to server-side scripts for furtherprocessing.

  1. Building Web Forms In Flash
  2. Access Granted
  3. Alien Invasion
  4. Loading Up
  5. Coming Back For More
  6. A Fine Balance
By: icarus, (c) Melonfire
Rating: starstarstarstarstar / 323
August 07, 2002

print this article


The example you just saw submitted the user's input to a PHP script, thereby redirecting the browser to a fresh page. In case you'd like this result page to also be generated in Flash, Flash MX includes a new ActionScript function named sendAndLoad(), which allows you to submit form data to a server-side script and read the response back into the Flash movie for further processing. This response can then be used to build a new Flash movie on the fly.

If this seems like alien technology to you, don't be afraid - it's not very difficult to do. First, you need to set up your server-side script so that it returns a set of variable-value pairs as URL-encoded form data - as the following example demonstrates:

These variables can then be read into Flash and used to assign values to variables within the Flash movie.

Consider the following revision of the ActionScript code above, which demonstrates the process:

function doSubmit() { userData = new LoadVars(); userData.name = name; userData.species = species; userData.speciesType = speciesType.getValue(); userData.residence = residence.getValue(); response = new LoadVars(); response.onLoad = getResponse(); userData.sendAndLoad("register.php", response, "post"); } function getResponse(result) { if(result == true) { // use result values } else { // display error } }
In this case, a new instance of the LoadVars() object has been created, this one designed to hold the variable package returned by the server-side script. When this response is received by the Flash movie, the onLoad event handler is triggered, and the getResponse() function invoked.

Note the difference in the technique used to actually submit the form data to the server - the previous example used the send() method, which only submitted the data, while this one uses the sendAndLoad() method, which both submits data and accepts a response.

The getResponse() function returns an object, whose properties correspond to the variables returned by the server-side script. So, if the server-side script returned the string,

which contains the variables "color" and "red", I could modify the getResponse() function above to use them like this:

function getResponse(result) { if(result == true) { set("itemInstance.color", result.color); set("itemInstance.shape", result.shape); } else { // display error } }
In this case, variables within the Flash symbol "itemInstance" are being set to the values returned by the server-side script "register.php", via the set() method.

>>> More Flash Articles          >>> More By icarus, (c) Melonfire

blog comments powered by Disqus
escort Bursa Bursa escort Antalya eskort


- An Overview of Flash and ActionScript
- Building Web Forms In Flash
- Building Data-Driven Flash Movies
- Flash 101 (part 6): The Final Countdown
- Flash 101 (part 5): Spiralling Out Of Control
- Flash 101 (Part 4): Don't Touch Me!
- Flash 101 (part 3): Bouncing Around

Developer Shed Affiliates


Dev Shed Tutorial Topics: