LoadVars Variable Return Problem?

Post here your questions about Actionscript and Java server side extensions development.

Moderators: Lapo, Bax

Post Reply
coolboy714cp
Posts: 323
Joined: 06 Feb 2010, 02:45
Contact:

LoadVars Variable Return Problem?

Post by coolboy714cp »

In my extension, I'm loading a variable called iM to my extension from a PHP page, so I'm using LoadVars on the server.

What would be the best way to return the iM variable, and where would I put the coding at?

Code: Select all

...
function lV(urlToLoad, targetUser) {
	var _send = new LoadVars()
	var _load = new LoadVars()
	
	// Set parameters to send
	_send.mN = String(targetUser);
	
	// Handle the remote data
	_load.onLoad = function(success, errorMsg)
	{
		if (success)
		{
			trace("Data received:")
			
			trace("iM    : " + this.iM)
			iM = this.iM;
			trace("iM 1 = " + iM);
			return iM;
		}
		else
		{
			trace("Loadvar Failed. " + errorMsg)
		}
	}
	
	// Send data with POST method and receive it back in the _load object
	_send.sendAndLoad(urlToLoad, _load, "post")
}
...
The reason I'm asking this is because currently, the return code isn't working, although when I trace the variable it traces out correctly.

The return code I'm currently using in the coding above comes out to undefined, rather than the correct value that is being traced.

Does anyone know why and/or how to fix it?
BigFIsh
Posts: 1698
Joined: 25 Feb 2008, 19:26
Location: New Zealand

Post by BigFIsh »

Smartfox's forum is my daily newspaper.
coolboy714cp
Posts: 323
Joined: 06 Feb 2010, 02:45
Contact:

Post by coolboy714cp »

I just setup my crossdomain on my webhost, and it is still returning undefined. - http://mechmicecheats.org/crossdomain.xml
BigFIsh
Posts: 1698
Joined: 25 Feb 2008, 19:26
Location: New Zealand

Post by BigFIsh »

Can you show us how you're sending the data back to your extension from php?
Smartfox's forum is my daily newspaper.
coolboy714cp
Posts: 323
Joined: 06 Feb 2010, 02:45
Contact:

Post by coolboy714cp »

Code: Select all

<?php
$var = $_POST["mN"];

$con = @mysql_connect("localhost", "dbadmin1", "*password*") or die("");

if ($con) {
	@mysql_select_db("testdb1", $con);
	$query = @mysql_query("SELECT * FROM testTable WHERE username='$var' LIMIT 1;", $con);
	$res = @mysql_fetch_assoc($query);
	$resIM = $res["ismember"];
	if ($res["username"] == $var) {
		print "&iM=$resIM&mN=$var";
	} else {
		print "&iM=false&mN=$var";
	}
} else {
	print "&iM=false&mN=$var";
}
?>
I'm just using a regular PHP code to print out the variables.
BigFIsh
Posts: 1698
Joined: 25 Feb 2008, 19:26
Location: New Zealand

Post by BigFIsh »

The php looks alright to me.

Looking at your sendAndLoad code, you appear to have two LoadVars. I think you should only need one.

Have you tried the example provided in http://forums.adobe.com/message/2659798#2659798?
Smartfox's forum is my daily newspaper.
coolboy714cp
Posts: 323
Joined: 06 Feb 2010, 02:45
Contact:

Post by coolboy714cp »

Alright, I will try to do that after I setup my server. But the coding I posted above in my extension was from the loadVarsTest.as example file.
Post Reply