Skip to main content
April 21, 2006
Answered

Why lVars.sendAndLoad does not work!!!

  • April 21, 2006
  • 5 replies
  • 478 views
Hello,

I am trying to get a response from a php script, but lVars.onLoad is never fired. I checked the url using my browser and it works fine, but can't get it work from Flash.

I will appreciate any help.

---- The code -------
AS:
stop();
var lVars:LoadVars = new LoadVars();
var int_id:Numeric;

lVars.onLoad = function(ok:Boolean) {
trace("OnLoad");

this.displayMessage = function(success) {
trace("DisplayMessge");

if (success) {
lblMessage.text = this.message;
} else {
lblMessage.text = "Failed";
}
trace("Message: "+lblMessage.text);
}

this.displayMessage(ok);
};

this.runScript = function() {
trace("Run Script");
//lVars.message = "";
lVars.sendAndLoad(" http://223.0.0.60/Flawless/medallionAlerts.php", lVars, "POST");
trace("PHP Sent. Message: " + lVars.message);
};

int_id = setInterval(this, "runScript", 1000*10);
trace("Interval set");


PHP:
<?
error_reporting(0);
session_start();
include_once("includes/incDb.php");
include_once("includes/functions.php");

$link=db_connect();
$id = 10;
$message = getMedPrivLink($id);
echo ("&message=" . $message);
?>

What am I missing?

Thank you,

Carlos
This topic is closed to new replies. Start a new post to keep the conversation going.
Correct answer Peter Lorent
Is the url correct? Or is it a fake url?
I'm using the code attached (and it works fine). FTP the PHP-code to a domain and first establish the connection.

5 replies

April 21, 2006
Hi LuigiL,

I found the problem. The php script and the onLoad were working fine.
The problem was that I was trying to return a link to another url and it had few parameters, so Flash got confused with the "&" contained in the link.

I changed the php script to return strings with no "&" then put the link together inside Flash.

Something that was really helpful to discover the problem was to do a trace of the LoadVars object. It displayed all properties and values. So, I found out it where the problem was.

By the way, I tested using an IP and a domain name once I found it was working. It make no difference. I am using Linux RH 8 and IE 6.

I really appreciate your help.

Carlos

Inspiring
April 21, 2006
You're welcome. It's always hard trying to find the error with server side scripting. That's why I was asking for your php script. But, good you solved it! Good luck.
April 21, 2006
Hi LuigiL,

Thank you for helping me with this.

I fixed the typo change the variable from lVars to lVars_lv and created the object separately from definition as follows:
---- Oringinal code -----
var lVars:LoadVars = new LoadVars();
var int_id:Numeric;

---- New code ----
var lVars_lv:LoadVars;
var int_id:Number;

lVars_lv = new LoadVars();

changed the sendAndLoad invocation to use a domain name instead of an ip as follows:
---- origiinal code -------
lVars.sendAndLoad(" http://223.0.0.60/Flawless/medallionAlerts.php", lVars, "POST");
trace("PHP Sent. Message: " + lVars.message);

----- new code --------
I also initialized the message property before invoking the php script as below:

lVars_lv.message = "OldValue";
trace("Old message: " + lVars_lv.message); // displays OldValue
lVars_lv.sendAndLoad(" http://testingsite.com/Flawless/medallionAlerts.php", lVars_lv, "POST");
trace("message: " + lVars_lv.message); // displays nothing


Now the onload event is fired, but nothing is returned in the message property.

What do you think?

Carlos
Peter LorentCorrect answer
Inspiring
April 21, 2006
Is the url correct? Or is it a fake url?
I'm using the code attached (and it works fine). FTP the PHP-code to a domain and first establish the connection.

Inspiring
April 21, 2006
>>var int_id:Numeric;
Typo. Should be:
var int_id:Number;
Your onLoad doesn't fire because the call to the php-file never gets made. The script works fine if you use a 'normal' url and not an IP-address:
lVars.sendAndLoad(" http://www.yoursite.com/Flawless/medallionAlerts.php", lVars, "POST");