views:

171

answers:

2

Hi,

Ive made a query in PHP, and I'm trying to send the results back into Flash via AS3, but it's throwing up this error...

Error: Error #2101: The String passed to URLVariables.decode() must be a URL-encoded query string containing name/value pairs. at Error$/throwError() at flash.net::URLVariables/decode() at flash.net::URLVariables() at flash.net::URLLoader/onComplete()

Here is the relevant part of the PHP and AS3 code, including the query. The Flash variable rssAdd is passed over to the PHP which is using it in the PHP query accordingly.

$url = $_POST['rssAdd'];
$query= SELECT title
FROM Feed
WHERE category = (SELECT category
FROM Feed
WHERE url =$url) AND url!=$url;
$result = mysql_query($query);
echo  $query;

Here is the AS3 code I've done so far.

function recommendation(){

var request:URLRequest = new URLRequest("url");
request.method = URLRequestMethod.POST

var recVars:URLVariables = new URLVariables();

recVars.rssAdd=rssAdd;
request.data = recVars

var loader:URLLoader = new URLLoader(request);
loader.addEventListener(Event.COMPLETE, onComplete);
loader.dataFormat = URLLoaderDataFormat.VARIABLES;
loader.load(request);

function onComplete(event:Event):void{
recommend.text = event.target.data;
}
 } 

Any help would be most appreciated, thanks.

+1  A: 

Have you checked what is coming back from the server running your PHP application? Checking the details of the request and the response, using Firefox and the Net panel of Firebug, could shed light on some other unexpected problem with the web server.

danyal
The response from the PHP file is the query itself, the same response i get if I trace event.target.data.title in flash. Does that shed any more light on my problem? thanks.
Dale J
That's clearer. What class is your 'recommend' variable?
danyal
Not quite sure what you mean. The variable rssAdd is a String, containing a url.
Dale J
In your onComplete() handler you have a variable called "recommend". What class is it and where was it declared (or was it dragged onto the stage in the IDE)? This could be a scope problem - first check that Publish Settings -> Flash -> Settings -> Strict Mode is checked. Also try moving onComplete() out of recommendation(). Rename it if necessary.
danyal
Also try changing "loader.dataFormat = URLLoaderDataFormat.VARIABLES;" to "loader.dataFormat = URLLoaderDataFormat.TEXT;"
danyal
Oh I see, its text using the text tool.Its finding onComplete, since I put the trace in there.
Dale J
It must be something to do with PHP surely? If its returning the query itself,and not the result?
Dale J
The last line of your PHP script is "echo $query" rather than "echo $result". Could that be it?
danyal
It still giving me the url encoding problem, since flash wants name-value pairs. I went down this road as well, to no avail. $result = mysql_query($query);while($row = mysql_fetch_assoc($result){return urlencode.$row['title']};
Dale J
Saw you fixed it. Good stuff.
danyal
+1  A: 

Fixed it with the following return:

$result = mysql_query($query);
$row=mysql_fetch_array($result);
print ("recTitle=".urlencode($row['title']));
Dale J