LoadVars - communication with a server
Hi All,
I'm really newbie of Flash Lite, but i did something with Flash in the past. So If I said something completely wrong, be patient... :o
I would like to exchange data with a server. My mobile should take the path of an image. It sends some data (var1, var2) to a php server and the server answers with a string that is a path.
I implemented this with the following code:
[CODE]on(release){
var envelope:LoadVars = new LoadVars();
var envelope_rcv:LoadVars = new LoadVars();
envelope.val1 = '41.5';
envelope.val2 = '12.3';
envelope.sendAndLoad("http://www.mywebsite.com/try.php",envelope_rcv,"GET");
_root.text1 = envelope_rcv.path;
}[/CODE]
_root.text1 is undefined after I press the button. :(
Is there any error according to you?
How would you deliver that issue?
Thank you
Re: LoadVars - communication with a server
Hi,
The written code does not give sufficient time for sending the data across the network and receiving the result.
[CODE]
envelope.sendAndLoad("http://www.mywebsite.com/try.php",envelope_rcv,"GET");
_root.text1 = envelope_rcv.path;[/CODE]
You can rewrite this piece of code using the [I]"onLoad"[/I] event handler. This handler is invoked after the implementation of [I]sendAndLoad[/I]. Moreover, it is not necessary to have 2 [I]LoadVars[/I] instances.
[CODE]
url = "http://www.mywebsite.com/try.php";
var envelope:LoadVars = new LoadVars();
envelope.val1 = '41.5';
envelope.val2 = '12.3';
envelope.sendAndLoad(url,envelope,"POST");
envelope.onLoad = function(success){
//assuming path is the result returned from php
_root.text1 = this.path;
}
[/CODE]