As3 uses amfphp to communicate with PHP

Source: Internet
Author: User

First, let's talk about the specific configuration. php version: 5.2.5, Apache: 2.2.11, amfphp: 1.9, and Windows XP.

Note: different versions of amfphp may conflict with those of PHP. The specific detection method is: Decompress amfphp in the web root directory and access this URL: http: // localhost/amfphp/Browser/. If no error is reported, congratulations. If any error occurs, replace the amfphp version.

After my test, the configuration above will not be faulty.

Procedure:
1. Declare a netconnection and select the amf3 protocol. Currently, amf3 is generally used.
2. Declare a responder object that is used in netconnection. Call () to process the return values from servers related to the success or failure of a specific operation.
3. Use netconnection. Call () to read the methods in PHP. netconnection. Call (command: String, responder: responder ).
The first of the two function parameters in responder. If the server is successfully called and the result is returned, the function is called. Onsuccess in this example.

Second, if the server returns an error, this function is called. In the example, onerror.

 

1 package 2 {3 Import flash. display. sprite; 4 Import flash. events. *; 5 import flash.net. netconnection; 6 Import flash.net. objectencoding; 7 Import flash.net. responder; 8 9/** 10 *... 11*12*13 */14 public class aswithphp_2 extends sprite 15 {16 private var connection: netconnection = new netconnection (); 17 private var RSP: responder = new Responder (onsuccess, onerror); 18 private var phpurl: String = "php address"; // note that it is a string instead of urlrequest19 20 public function aswithphp_2 () 21 {22 Init (); 23} 24 25 private function Init (): void 26 {27 connection. objectencoding = objectencoding. amf3; // select amf3 Protocol 28 connection. addeventlistener (netstatusevent. net_status, onnetstatus); 29 connection. connect (phpurl); // connect to the backend PHP address 30 connection. call ("methods in PHP", RSP); 31} 32 33 private function onnetstatus (E: netstatusevent): void 34 {35 switch (e.info. code) {36 case "netconnection. connect. success ": 37 trace (" connection successful "); 38 break; 39 40 case" netstream. play. streamnotfound ": 41 trace (" not found: "+ phpurl); 42 break; 43} 44} 45 46 private function onsuccess (OBJ: Object ): void {47 trace ("OK:" + OBJ); 48} 49 50 private function onerror (_ OBJ: Object): void {51 trace ("error "); 52} 53} 54 55}

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.