Now, when talking about the interaction between as3 and PHP, the first response will come to the idea of AMF.
In fact, AMF is just an information background written in PHP or other languages,
Returning to the original, communication is nothing more than these methods.
(1) Direct Reading
PHP:
<?
$ State = "start receiving ";
$ Var1 = "received ";
Echo "state =". $ state. "& var1 =". $ var1;
?>
As:
// BTN is a button. txt is a dynamic text. Create it in flash and click OK.
BTN. addeventlistener (mouseevent. Click, loadmss );
TXT. Text = "loading ...";
Function loadmss (E: mouseevent): void
{
VaR urlloader: urlloader = new urlloader ();
Mssloader. dataformat = urlloaderdataformat. variables;
Mssloader. Load (New URLRequest ("http: // localhost/as3/admin. php"); // This is the address of the PHP file.
Mssloader. addeventlistener (event. Complete, completefun );
}
Function completefun (E: Event): void
{
VaR loaddata: urlvariables = urlvariables (E. currenttarget as urlloader). DaTa );
TXT. Text = "in progress:" + loaddata. State + "\ n ";
TXT. Text + = "receipt:" + loaddata. var1;
}
(2) read the XML generated by PHP
PHP:
<?
// Here is a simple echo.
Echo "<? XML version = \ "1.0 \" encoding = \ "UTF-8 \"?> ";
Echo "<pics> ";
Echo "<P1> 1.jpg</P1> ";
Echo "<P2> 2.jpg</P2> ";
Echo "</pics> ";
?>
As:
// BTN is a button. txt is a dynamic text. Create it in flash and click OK.
BTN. addeventlistener (mouseevent. Click, loadmss );
Function loadmss (E: mouseevent): void
{
VaR urlloader: urlloader = new urlloader ();
Xmlloader. Load (New URLRequest ("http: // localhost/as3/XML. php"); // This is the address of the PHP file.
Xmlloader. addeventlistener (event. Complete, completefun );
}
Function completefun (E: Event): void
{
VaR loaddata: xml = XML (E. currenttarget as urlloader). DaTa );
TXT. Text = loaddata. tostring ();
}
(3) pass out parameters through get
// BTN is a button. txt is a dynamic text. Create it in flash and click OK.
System. usecodepage = true;
BTN. addeventlistener (mouseevent. Click, loadmss );
Function loadmss (E: mouseevent): void
{
VaR getloader: urlloader = new urlloader ();
VaR request: URLRequest = new URLRequest ();
Request. url = "http://enatool.com/something.php"; // here is the address for receiving Parameters
Request. method = urlrequestmethod. Get; // outgoing Method
Request. DaTa = "s = 1"; // transmit the specific information
Getloader. Load (request );
Getloader. addeventlistener (event. Complete, completefun );
}
Function completefun (E: Event): void
{
TXT. Text = (E. currenttarget as urlloader). DaTa;
}
(4) passing parameters through post
// BTN is a button. txt is a dynamic text. Create it in flash and click OK.
System. usecodepage = true;
BTN. addeventlistener (mouseevent. Click, loadmss );
Function loadmss (E: mouseevent): void
{
VaR postloader: urlloader = new urlloader ();
VaR request: URLRequest = new URLRequest ();
VaR vars: urlvariables = new urlvariables ();
Vars. S1 = "Flash ";
Vars. S2 = "flex ";
Request. url = "http://enatool.com/something.php ";
Request. method = urlrequestmethod. post;
Request. DaTa = vars; // The data here can be an object or Array
Postloader. Load (request );
Postloader. addeventlistener (event. Complete, completefun );
}
Function completefun (E: Event): void
{
TXT. Text = (E. currenttarget as urlloader). DaTa;
}
It interacts with PHP or ASP or. NET information. Therefore, do not look at interaction as hard.
(If You Want To reprint it, please specify the source at http://blog.sina.com.cn/jooi. Thank you)