PDA

View Full Version : Need help on sendAndLoad


dreams83
07-03-2007, 10:37 PM
I am trying to get sendAndLoad to get url from a php script but I it seem like sendAndLoad will only return my the url after the process finished loading and I want it before that happens. Can you use help me?

here is the swf of what it is doing:

http://www.ehmongmusic.com/testsendv1.swf

here is the fla file:

http://www.ehmongmusic.com/testsendv1.fla

here is the code:
//---------------

var submitListener:Object = new Object();
submitListener.click = function(evt:Object) {
bug_ta.text += "[Submit Click: "+name_ti.text+"]\n";
var xy = ehm_url(name_ti.text);
trace(xy);
result_ta.text = xy;
bug_ta.text += "[Result: "+xy+"]\n";
};
submit_button.addEventListener("click", submitListener);

function ehm_url(idsong){
bug_ta.text += "[Function Call: " + idsong+"]\n";
//var file_url:String = "";
var result_lv1:LoadVars = new LoadVars();
result_lv1.onLoad = function(success:Boolean) {
if (success) {
bug_ta.text += "[Success Call: " + result_lv1.id+"]\n";
trace(this.result_lv1.id);
return this.result_lv1.id;

} else {
return "Error connecting to server.";
}
};
var send_lv1:LoadVars = new LoadVars();
send_lv1.idsong = idsong;
send_lv1.sendAndLoad("http://www.ehmongmusic.com/flashurl.php", result_lv1, "POST");
};

here i made a little textarea to show when different functions are called:


[Submit Click: 456]
[Function Call: 456]
[Result: undefined]
[Success Call: http://www.ehmongmusic.com/albums/music/MaivMuasKwm/Maiv_Muas_Kwm_-_Hmoob_tshiab_peb_caug.mp3]

----------------
from this what I wanted it to do it is have Success Call before the Result: so that I will have something in the result but it seem like it is not doing that. The sendAndLoad seems to be executing last so when I want result there is nothing there.

If you guys and girls could help me that would be much appreciate.

Thank You

justinbird
07-04-2007, 12:01 AM
first of all you're using:
return this.result_lv1.id;

in this instance this is the same as result_lv1, so you're returning result_lv1.result_lv1.id (which doesn't exist). Just use:
return this.id

but that won't solve your problem. sendandload is asynchronous - meaning, the script will continue to run after you call sendandload. It won't just stop and wait for the data to come in. Anything you're doing with the result code should happen within the onLoad section to ensure that the data is loaded before continuing.