Flex 4.6 and Amfphp 2.2.1 Simple Notes (a): Environment construction

Source: Internet
Author: User

Http://sourceforge.net/projects/amfphp/files/amfphp-2.2.1.zip/download

Download amfphp, as of 2015.5.16, the latest version is 2.2.1

Get a compressed package, according to the official instructions, you only need to deploy the amfphp-2.2.1/amfphp directory to the server side to use, if necessary, you can also deploy the Amfphp-2.2.1/backoffice directory, Use amfphp's servicebrowse and other functions, see the official documentation for details.

Here I will deploy the amfphp in the wamp/www/directory on the local Wamp server, unzip the compressed package, and get the amfphp-2.2.1 directory, including amfphp, BackOffice, and documents and instances.

This gives the wamp/www/amfphp-2.2.1/amfphp, Wamp/www/amfphp-2.2.1/backoffice,

Wamp/www/amfphp-2.2.1/doc and other catalogs.


Create a new Flex project, Project options, Flex server Technology Select PHP, fill in the server location and output folder location

650) this.width=650; "src=" http://s3.51cto.com/wyfs02/M02/6C/F0/wKiom1VW-mniKyLCAADd3HEwLRU405.jpg "title=" 1.jpg " alt= "Wkiom1vw-mnikylcaadd3hewlru405.jpg"/>

Create an XML file named Services-config.xml, placed under the Flex Project source src folder, with the following XML content

<?xml version= "1.0" encoding= "UTF-8"? ><services-config><services><service id= " Amfphp-flashremoting-service "class=" Flex.messaging.services.RemotingService "messagetypes=" Flex.messaging.messages.RemotingMessage "><destination id=" amfphp "><channels><channel ref=" amfphp "/></channels><properties><source>*</source></properties></ Destination></service></services><channels><channel-definition id= "amfphp" class= " Mx.messaging.channels.AMFChannel "><endpoint uri=" http://localhost/ordersystem/gateway.php "class=" Flex.messaging.endpoints.AMFEndpoint "/></channel-definition></channels></services-config>

Note that endpoint uri= "xxxxxx" here to fill in the location of your amfphp gateway PHP file, which I named gateway.php in the project root directory ordersystem/

Project Properties-flex Compiler-Additional compiler parameters, add-services services-config.xml parameter


Then explain the content of gateway.php, according to the official note, amfphp by default in its own deployment Directory Services subdirectory to find the service, in order to put the flex PHP communication with PHP files in the release directory of the Flex project, instead of mixing in the amfphp deployment directory, we need to customize The configuration of the semantic amfphp. In the Flex project's publish directory wamp/www/ordersystem/, create a gateway.php file, in fact the name is arbitrary, just note that the Flex project in Services-config.xml, endpoint The URI property to correspond to the directory location and file name of this file.

<?phprequire_once (DirName (__file__). ' \.. /amfphp-2.2.1/amfphp/classloader.php '), $config =new amfphp_core_config (); $config->servicefolders=array ( DirName (__file__). ' /services/'); $gateway =amfphp_core_httprequestgatewayfactory::creategateway ($config); $gateway->service (); $ Gateway->output ();? >

gateway.php, use require_once and dirname to find and reference classloader.php in amfphp, create an instance of the Amfphp_core_config class, set the location of the custom lookup amfphp service class, This is set to the Services subdirectory under the Flex Project publishing location directory. and then call

Amfphp_core_httprequestgatewayfactory::creategateway ($config), create the gateway, and then call the service and output methods.

In this way, the basic configuration of amfphp is complete, and the Flex Project publish directory's Services subdirectory is wamp/www/ordersystem/services/, creating a custom PHP service class that exposes public methods that can be called by flex remotely.


In Flex 4.6, you can use the Netconnect class or the RemoteObject class to invoke the server-side PHP method.

This illustrates the use of remoteobject.

<fx:Declarations><!--Place non-visual elements (such as services, value objects) here--><s:remoteobject id= "Versionro" destination= "amfphp" Source= "GetVersion" ><s:method name= "getversion" result= "Onversionget (event)" fault= "Alert.show ( event.fault.faultString); "/></s:remoteobject></fx:declarations>

In application Mxml for Flex 4.6, in fx:declarations, define RemoteObject, and note that destination is set to Amfphp,source in wamp/www/services/ Service the custom class name in the php file.

The S:method property defines the name of the service method advertised by the class, and the result event handler is set to the function that processes the data after the call succeeds, fault the event handler after the failed call

You can then use the RemoteObject instance. Method (parameter) to invoke the server-side advertised service method

For example, Versionro.getversion () can be called here;

Flex 4.6 and Amfphp 2.2.1 Simple Notes (a): Environment construction

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.