Flex and AMFPHP

Questions regarding AIR and Flex.

Flex and AMFPHP

Postby bennyhill » Sat Aug 09, 2008 2:57 am

I am just starting in Flex and I also just watched Lee's tutorial's on AMFPHP. For Flex to call functions from a php file that interacts with a database, do I need AMFPHP for this? Or does Flex already have what it needs to exchange AMF data with a php file?
bennyhill
 
Posts: 18
Joined: Sat Aug 09, 2008 2:50 am
Flash Version: Adobe Flash CS5

Re: Flex and AMFPHP

Postby bebo925 » Sat Aug 09, 2008 11:39 am

There are 3 ways for flex to call remote procedures. I use remote object in conjunction with AMFPHP. it is still easy to set up and even easier to use. it takes like half the code.

Setup:
you need to add an xml file called services-config.xml to your src folder and edit one line of code where it says yourdomainhere (you can copy this from project to project)
Code: Select all
<?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="my-amfphp"/>
            </channels>
            <properties>
               <source>*</source>
            </properties>
         </destination>
      </service>
   </services>
   <channels>
      <channel-definition id="my-amfphp" class="mx.messaging.channels.AMFChannel">
         <endpoint uri="http://www.yourdomainhere.com/amfphp/gateway.php" class="flex.messaging.endpoints.AMFEndpoint"/>
      </channel-definition>
   </channels>
</services-config>


you need to add a command under Project Properties->Flex Compliler->Addition Compile Arguements:-services "services-config.xml"
the entire line looks like: -locale en_US -services "services-config.xml"

do the usual AMFPHP setup

Flex:
Code: Select all
 <mx:RemoteObject id="instanceName"  source="phpClassName" destination="amfphp">
        <mx:method name="methodName"  result="makeAFunction()"/>
       </mx:RemoteObject>


and you call the method with:
Code: Select all
instanceName.getOperation("methodName").send(parameters)
User avatar
bebo925
 
Posts: 544
Joined: Tue Aug 22, 2006 2:51 am
Flash Version: Adobe Flash CS5.5
Authoring Environment: Microsoft Windows


Return to AIR and Flex

Who is online

Users browsing this forum: No registered users and 1 guest