Communication between flash as3 and PHP

Source: Internet
Author: User

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)

Contact Us

The content source of this page is from Internet, which doesn't represent Alibaba Cloud's opinion; products and services mentioned on that page don't have any relationship with Alibaba Cloud. If the content of the page makes you feel confusing, please write us an email, we will handle the problem within 5 days after receiving your email.

If you find any instances of plagiarism from the community, please send an email to: info-contact@alibabacloud.com and provide relevant evidence. A staff member will contact you within 5 working days.

A Free Trial That Lets You Build Big!

Start building with 50+ products and up to 12 months usage for Elastic Compute Service

  • Sales Support

    1 on 1 presale consultation

  • After-Sales Support

    24/7 Technical Support 6 Free Tickets per Quarter Faster Response

  • Alibaba Cloud offers highly flexible support services tailored to meet your exact needs.