| If your flash movie needs
to send and load dynamic data to/from your web server,
you have to write some actionscripts. Since Flash MX,
the LoadVars Object provide a handy way to send and
load data to/from your web server.
Example 1 - send
To send data back to your server, you can write:
var sender = new LoadVars();
sender.x = "xxx";
sender.y = "yyy";
sender.z = "zzz";
sender.send("http://www.yourdomain.com/yourscript.php",
"", "post");
|
which create the LoadVars object, set the variables
(i.e. x="xxx", y="yyy" and z="zzz")
and send them back to the server script (in HTTP POST
method) for processing. (NOTE: you are not restricted
to use "post", you can use "get"
as well.)
Example 2 - sendAndLoad
In case you want to get back data at the same time
you send your data back to the server, you can use the
sendAndLoad api:
var loader = new LoadVars();
loader.onLoad = function(success) {
if(success) {
// read your data here,
e.g.
trace(this.x); // suppose
the server send back a variable x
trace(this.y); // and
a variable y
}
}
var sender = new LoadVars();
sender.x = "xxx";
sender.sendAndLoad("http://www.yourdomain.com/yourscript.php",
loader, "post");
|
The first line creat a loader object which is required
by the sendAndLoad api. Then we define the event handler
for the onLoad event (When the loader received data
from the server, the event handler will be called).
Then we set up the sender as in the previous example,
call the sendAndLoad api...
Of course, if you just want to load some data from
your server, it is simplier, you can use similar code
as above, but instead of setting up the sender LoadVars
object, you can just write: loader.load("http://www.yourdomain.com/yourscript.php");
You can then get the data from within the onLoad event
handler.
< Tutorials
Index - Post
suggestions >
|