You want to load variables from an external text file into your Flash movie.
Use the URLLoader.load()
method in conjunction with DataFormat.VARIABLES
as the dataFormat
to read URL-encoded data into a
Flash movie.
You should use the URLLoader.load() method whenever you want to load URL-encoded data into your Flash movie from a text file. This technique allows your Flash movie to access values that frequently change without modifying the Flash movie itself.
The load() method
requires a URLRequest instance as
a parameter that points to the URL of the text file. The URL can be an
absolute or relative address. Additionally, the URLLoader needs to be configured to
interpret the text as URL-encoded variables instead of plain text.
Setting the dataFormat
property of
the URLLoader instance to the
DataFormat.VARIABLES
constant
accomplishes this. Here is code to illustrate loading data from a text
file:
import flash.net.*; // You must first create theURLLoader
object. var example:URLLoader = new URLLoader(); // Configure the instance to interpret data as URL-encoded variables example.dataFormat = DataFormat.VARIABLES; // This example loads values from a text file at an absolute URL. example.load( new URLRequest( "http://www.darronschall.com/example.txt" ) ); // This example loads values from a text file located at a relative // URL, in this case, in the same directory as the.swf
file. example.load( new URLRequest( "example.txt" ) ); ...
No credit card required