1

I've got an actionscript code supposed to run a php script which, to make sure the error is not on it but on the AS code, I've reduced to creating a plain text file. After the line supposed to call the php script, I've got a call to 'trace' in order to make sure that the line is run. Given this, looks like 'the script is run', but there's no new file.

Here's the important code:

AS

const iURL:String = "i.php";
var myLoader:URLLoader = new URLLoader();
myLoader.load(new URLRequest(iURL));

php

$ourFileName = "playlistTEST.xml";
$ourFileHandle = fopen($ourFileName, 'w') or die("can't open file");
fwrite($ourFileHandle,"CREATED");
fclose($ourFileHandle);

2 Answers 2

1

You could try adding event.complete on your AS code

var myRequest:URLRequest = new URLRequest("http:// ... /i.php");
myLoader = new URLLoader();
myLoader.addEventListener(Event.COMPLETE, onLoad);
myLoader.load(myRequest);

function onLoad(evt:Event):void
{
    trace(myLoader.data);
}

Also did you open the php file though the browser yet? You should probably test that first before calling it with AS.

Remember that AS uses normal HTTP request method, so the result is the same as when you open it in the browser.

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

7 Comments

In the browser it works. I've added your suggestion (changing the funcion name, since onLoad looks like a reserved word and I was getting a compiler error) but no new trace output is generated.
Thats probably because your PHP file isnt outputting any text, try some echo's
It makes no difference. I've also added an EVENT.ACTIVATED handler, but it is not triggered for that request (it does for another later request with the same loader, as the EVENT.COMPLETE request does).
... Could it be you actually left i.php in there? in order to run php it has to go through a webserver you cant call the file directly. in case you are using a localhost it would be http://localhost/project_folder/i.php
Ok gotta fix apache then. Thanks.
|
0

refer a following code.

var urlRequest:URLRequest = new URLRequest("http://...php");
urlRequest.method = URLRequestMethod.GET;

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

function onCompleteHandler(e:Event)
{

}

3 Comments

Tried it but no difference. The only think I can think of is that I'm referring the php file locally, but right now I've got a problem in my computer so I can't set Apache up and therefore I can't work with localhost. Could the problem be because of the local reference?
.php files in the same folder as the .fla file is this?
Yes. I know there may be some kind of security issues when trying to modify files in the app folder from the .fla but since the modification is performed from the php file, I don't think that's a problem...

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.