Working with external data in Flash - getURL(), loadVariables(),loadVariablesNum(), loadMovie(), and loadMovieNum() methods
(Page 2 of 6 )
The methods listed as the title of this section use the HTTP or HTTPS protocol to send information in URL-encoded format.
getURL(): This method loads a document from a specific URL into a window or passes variables to another application at a defined URL. This method can used when you want to load a different URL onto the existing one. You also have the option of passing the data to a different URL using http POST and GET methods.
Example:
//opens
http://www.devarticles.comin a blank window
getURL("http://www.devarticles.com", "_blank");
//sends the variables from flash to
http://www.devarticles.com
using POST method
getURL("http://www.devarticles.com", "_blank", ”POST”);
loadVariables() , loadVariablesNum():These methods reads data from any external file, such as a text file or text generated by any server-side scripting technology such as ColdFusion, CGI script, ASP, PHP, Perl, and so on, and set the values for variables in a Flash.
The main difference between the loadVariables() method and the loadVariablesNum() method is that loadVariables() sets the values for variables in a target movie clip, while loadVariablesNum() sets the values for variables in a level. You can also use this method to update variables in the active SWF file with new values.
The text in the text files, or the text generated by the server-side script, should be in the standard MIME format application/x-www-form-urlencoded (a standard format used by CGI scripts). Any number of variables can be specified, as in the string shown below.
name=Jhon&age=22&zip=534235
Example:
// Variables from data.txt will be loaded into target_mc movie clip
loadVariables("data.txt", target_mc);
// Variables from data.txt will be loaded into level 1
loadVariablesNum("data.txt", 1);
You can also use the movie clip’s loadVariables() method to load data directly into the movie clip.
Ex: target_mc. loadVariables ("data.txt");
loadMovie() , loadMovieNum(): These methods let you load external SWF files and JPEG files into the existing SWF file and are similar to loadVariables() and loadVariablesNum() methods. The difference between loadMovie() and loadMovieNum() is also the same, target and level.
Example:
// Loads play.swf file into target_mc movie clip
loadMovie("play.swf", target_mc);
// Loads play.jpg image into level 1
loadMovieNum("play.jpg", 1);
You can also use the movie clip’s loadMovie() method to load external SWF files or JPEG images into the movie clip directly.
Ex: target_mc.loadMovie("play.jpg");
Next: LoadVars Class >>
More Flash Articles
More By Adi Reddy Mora