PDA

View Full Version : loading data from an external script (same domain) fails


kaimar
10-31-2009, 11:49 PM
Hi,

Below is the script I'm using to pass a parameter to a script in the same server (and folder) as the flash file. It gives "null" as the required variable (use_url) value, instead of what the script is giving. The script itself works, when tested in a browser.

What it should do - it receives a value for "lesson_id" variable, passes it on to a script "movie_url" and receives a response with a new variable "real_url" and it's value.

What could be the problem?


function loadFinished(event:Event):void
{
use_url = event.currentTarget.data.real_url;
}

var myString:String = LoaderInfo(this.root.loaderInfo).parameters.lesson _id.toString();
var myVariables:URLVariables = new URLVariables();
myVariables.lesson_id = myString;
var myURL:String = "movie_url";
var request:URLRequest = new URLRequest();
request.url = myURL;
request.method = URLRequestMethod.GET;
request.data = myVariables;
var myLoader:URLLoader = new URLLoader();
myLoader.dataFormat = URLLoaderDataFormat.VARIABLES;

myLoader.addEventListener (Event.COMPLETE,loadFinished);
myLoader.load (request);

elytexeira
11-01-2009, 12:35 AM
How does your script passes your variable real_url? ... because the only way that i know to do that its via xml... and in your code i can't see how the script convertes the data received into a flash variable.

kaimar
11-01-2009, 12:45 AM
How does your script passes your variable real_url? ... because the only way that i know to do that its via xml... and in your code i can't see how the script convertes the data received into a flash variable.

The script's output is just one line in plain text, "real_url=xxxxx". In ActionScript the data is read in a variable-value format, defined by "myLoader.dataFormat = URLLoaderDataFormat.VARIABLES". AFAIK this is a working method and the data doesn't have to be in an XML format. I read the data then using "use_url = event.currentTarget.data.real_url" command.

kaimar
11-01-2009, 11:26 AM
Solution found - it was a matter of the order of commands in a function.