1

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
1
  • the same problem with using echo "resultVar=okay"? Commented Jun 19, 2015 at 20:32

2 Answers 2

2

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...

Sign up to request clarification or add additional context in comments.

2 Comments

I've checked link.php and It is opening in the browser and showing "resultVar = okay" so there is a no problem, I guess.
@ssorfonos Since a webserver doesn't really care about from where a request originates, you are most probably not loading the file from the server, as I mentioned, you might not be running your movie on/from the server, but in your local filesystem.
0

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);
}

Comments

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service and acknowledge you have read our privacy policy.

Start asking to get answers

Find the answer to your question by asking.

Ask question

Explore related questions

See similar questions with these tags.