Here is an example of using Flash AS3 to obtain remote PHP data. The data is obtained from the remote URL and then displayed in the Flash form text box. The example code is as follows:
1, AS3 part [Download]
package {
import flash.display.MovieClip;
import flash.events.*;
import flash.net.*;
import flash.text.*;
public class Main extends MovieClip {
public function Main() {
var request:URLRequest = new URLRequest("http://t.biuuu.com/index.php?nocache=");
request.method = URLRequestMethod.GET;
var loader:URLLoader = new URLLoader();
loader.dataFormat = URLLoaderDataFormat.VARIABLES;
loader.addEventListener(Event.COMPLETE, completeHandler);
loader.load( request);
function completeHandler(evt:Event) {
b_title.text = evt.target.data.username;
b_email.text = evt.target.data.email;
}
}
}
}
The implementation steps are as follows:
1. Get a URLRequest object instance
var request:URLRequest = new URLRequest(http://t.biuuu.com/index.php?nocache=);
Second, specify the method implemented by the request object, such as GET
request.method = URLRequestMethod.GET;
Three, get a URLLoader object instance
var loader:URLLoader = new URLLoader();
Four, set the data format of the loader object
loader.dataFormat = URLLoaderDataFormat.VARIABLES;
Fifth, set up a listening event when the PHP data acquisition is completed
loader.addEventListener(Event.COMPLETE, completeHandler);
6. Loading request
loader.load(request); To put it simply, it is to first clarify the attributes of the request URL, such as path address, request method, etc., and then set the implementation method of the returned data, such as data format , processing methods, etc.
2. PHP part [The path is http://t.biuuu.com/index.php, which can be modified according to the actual situation]
Pay attention to the assembly form of the data, similar to parameter = value. If there are multiple parameters, use & split
As shown in the above example, you can realize a simple function of using FLASH AS3 to remotely obtain PHP data. With this knowledge, you can start to implement a simple website based on AS3+PHP.
Click to download: as3_php.rar