As3 uses AMFPHP to communicate with PHP

Source: Internet
Author: User
As3 uses AMFPHP to communicate with PHP from: bbs.9ria.comthread-65836-1-1.html? First, let's talk about the specific configuration: PHP version: 5.2.5, apache: 2.2.11, (or WAMP2.2), amfphp: 1.9 (attachment already provided), and Windows XP. Note: different versions of amfphp may conflict with those of php. As3 uses AMFPHP to communicate with PHP

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

?

First, let's talk about the specific configuration: PHP version: 5.2.5, apache: 2.2.11, (or WAMP2.2), amfphp: 1.9 (attachment already provided), 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.

In a specific project, we sometimes use As3 pure projects, so Amf communication is also frequently used in as3. today we will talk about the methods in as3. (I have previously published articles about flex and amfphp Communications. please refer to the background section)
In As3, NetConnection is used. first, AMF3 protocol is used. this is commonly used. because AMF0 is compatible with previous versions, it has some redundancy.
Connect to the background url using the connect method.
Then declare a Responder object, which is used in NetConnection. call () to process the return values from servers related to the success or failure of a specific operation.
Next, use NetConnection and call methods in the php class in the background. for example, HelloWorld. getData, remember to write the declared Responder object to the 2nd parameters of the call method.

Note that the two function parameters in Responder are the first. if the server is successfully called and the result is returned, the function is called. OnSuccess in the example
Second, if the server returns an error, this function is called. In the example, onError.

Okay. let's take a look at As3:

Package {import flash. display. sprite; import flash. events. netStatusEvent; import flash.net. netConnection; import flash.net. objectEncoding; import flash.net. responder ;/***... * @ author Naran if */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:

 

The php file is named HelloWorld. php and placed in D: \ webroot \ amfphp \ services. (Note: D: \ webroot is my web root directory. the specific setting depends on your own .)

If the link is faulty, the following error may occur:

?

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 VerboseException: 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.0003 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

?

In this case, you only need to follow the prompts to open the gateway. php file and block the lines 135 and 137.

?

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.