As3 using amfphp and PHP progress communication

Source: Internet
Author: User
AS3 using amfphp to communicate with PHP

From: http://bbs.9ria.com/thread-65836-1-1.html

?

First, the specific configuration, PHP version: 5.2.5,apache:2.2.11, (or WAMP2.2), Amfphp : Version 1.9 (attachment provided), Windows XP system.

Note: Different versions of amfphp will conflict with different versions of PHP. The specific detection method is: In the Web root directory after extracting amfphp, access to the url:http://localhost/amfphp/browser/, if not reported any errors, then congratulations. If there is an error, please replace the amfphp version.

With my quiz, there's no problem with the configuration above.

in the specific Project , sometimes we use As3 pure projects, so in AS3, AMF communication is also often used, today we talk about the method in As3. (Previously sent flex and amfphp communication related articles, please refer to the background plate)
on the As3 side, mainly netconnection use, first select the use of AMF3 protocol, This is now commonly used, AMF0 because it is compatible with previous versions, so there is some redundancy.
Then use the Connect method to connect to the background URL. The
then declares a responder object that is used in Netconnection.call () to handle the return value from the that is related to the success or failure of a particular operation. The
then uses the method in the Netconnection,call background PHP end class, as in this case helloworld.getdata, remembering that the responder object being declared is written to the 2nd parameter of the call method.

Note the two function arguments in responder, first, if the call to the server succeeds and returns the result, the function is called. In the example onsuccess
The second one, if the server returns an error, this function is called. In the example, OnError.

OK, take a look at the AS3 side:

Package {import Flash.display.Sprite;    Import flash.events.NetStatusEvent;    Import flash.net.NetConnection;    Import flash.net.ObjectEncoding;    Import Flash.net.Responder; /** *. * @author Lanrong * * public class Amftest extends sprite{private var netcon:netconnection =        New Netconnection ();        private var rsp:responder = new Responder (onsuccess, onError);        private var phpurl:string = "http://localhost/amfphp/gateway.php";            Public Function Amftest () {netcon.objectencoding = OBJECTENCODING.AMF3;            Netcon.addeventlistener (Netstatusevent.net_status, onnetstatus);            Netcon.connect (Phpurl);        Netcon.call (' Helloworld.getdata ', RSP);        } Private Function Onnetstatus (e:netstatusevent): void {trace ("failed");        } Private Function Onsuccess (rspobj:object): void {trace ("OK:" +rspobj); } Private Function OnError ($RSPOBJ: Object): void {TRAce ("AMF client error."); }    }}

?

PHP Side:

 
  

The PHP file is named helloworld.php and placed in the D:\webroot\amfphp\services. (Note: D:\webroot is my web root, this particular setting depends on your own.) )

If there is a problem with the link, it may be caused by the following error:

?

Fatal error:uncaught exception ' verboseexception ' with message ' Standalone Flash player disabled. Update gateway.php to allow these connections ' in C:\wamp\www\amfphp\core\amf\app\Gateway.php on line 357 Verboseexceptio N:standalone Flash player disabled. Update gateway.php to allow these connections in C:\wamp\www\amfphp\core\amf\app\Gateway.php on line 357 call stack:0.000 3 374432 1. {main} () c:\wamp\www\amfphp\gateway.php:0 0.0062 874840 2. Gateway->disablestandaloneplayer () c:\wamp\www\amfphp\gateway.php:137 0.0062 875056 3. Trigger_error () c:\wamp\www\amfphp\core\amf\app\gateway.php:357 0.0062 875720 4. Amferrorhandler () c:\wamp\www\amfphp\core\amf\app\gateway.php:357

?

At this point only need to follow the prompts, open the gateway.php file, block out the original 135, 137 lines can be.

?

  • 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.