-1

Is it possible to pass information from PHP into Flash (AS3)? I need a PHP file and SWF that are in the same folder to communicate (I can't use an absolute link because I don't know where the files will be ultimately). I've made numerous attempts with two methods. I made posts on both but neither seem to work the way I need them to and I can't seem to get any help:

Passing Data from PHP to Flash

ActionScript 3.0 URLRequest with Relative Link

Since neither of these methods work, perhaps someone can give me one that can? To be clear, let's say in my PHP I have $name = "Bob"; without using an absolute link in Flash, is it possible to pass "Bob" to Flash to say, trace it or write it to a text field, and if so how?

Community
  • 1
  • 1

1 Answers1

1

I assume that you're talking about serving a SWF file and a PHP script from a server such as Apache, and that those sources are being accessed by client browser running Flash Player. You don't mention any server/client in your question.

That being the case, your SWF file (running in the client browser) can make an HTTP request to the PHP page on the server and pass data in the HTTP request, and the PHP script can return data in the HTTP response. You'd make the request using a URLLoader and URLRequest - here's a relevant tutorial. In your case, use a relative URL to access the PHP page:

var urlReq:URLRequest = new URLRequest ("script.php");

Or this:

var urlReq:URLRequest = new URLRequest ("./scripts/script.php");

However, without a request from the SWF client, the PHP cannot initiate communication to the browser client (SWF or otherwise).

Add a comment if you can clarify or have more specific questions.

Jeff Ward
  • 16,563
  • 6
  • 48
  • 57