Reputation: 108
I need to take some variables from PHP to AS3, but this is not working.
AS3 Code:
var urlLoader:URLLoader = new URLLoader;
var urlRequest:URLRequest = new URLRequest("link.php");
var urlVariables:URLVariables = new URLVariables;
urlLoader.dataFormat = URLLoaderDataFormat.VARIABLES;
urlRequest.method = URLRequestMethod.POST;
urlRequest.data = urlVariables;
urlLoader.addEventListener(Event.COMPLETE, urlCompleted);
urlLoader.load(urlRequest);
function urlCompleted(event:Event):void{
var urlLoaderOk:URLLoader = URLLoader(event.target);
urlLoaderOk.dataFormat = URLLoaderDataFormat.VARIABLES;
trace(urlLoaderOk.data.resultVar);
}
and this is the simple PHP Code:
<?php
print "resultVar=okay";
?>
I'm getting "undefined" result.
However, if I try
trace(urlLoaderOk.data);
like this, I'm getting this result
%3C%3Fphp%0D%0Aprint%20%22resultVar=okay%22%3B%0D%0A%3F%3E
Upvotes: 1
Views: 184
Reputation: 456
did you tried with full url like "http://some.where.com/location/of/link.php" in URLRequest ? and also try this code
function urlCompleted(event:Event):void{
var urlLoaderOk:URLLoader = URLLoader(event.target);
var urlvars:URLVariables = new URLVariables(urlLoaderOk.data);
trace(urlvars.resultVar);
}
Upvotes: 0
Reputation: 198
Your PHP code isn't interpreted as PHP, resulting in the whole files content to be returned (try to URL decode the data string), which of course isn't valid.
So, check what's wrong with your server, maybe it doesn't support PHP, maybe PHP is disabled, maybe the .php
extension isn't registered (that would be pretty weird though), maybe you're actually not testing this on a server at all, but in your local filesystem, etc...
Upvotes: 2