<?xml version="1.0" encoding="UTF-8"?>
<rss version="2.0" xmlns:dc="http://purl.org/dc/elements/1.1/">
  <channel>
    <title>DZone Snippets: remoting code</title>
    <link>http://snippets.dzone.com/posts</link>
    <pubDate>Thu, 21 Aug 2008 13:38:04 GMT</pubDate>
    <description>DZone Snippets: remoting code</description>
    <item>
      <title>Flash 8 AS2 REMOTING with AMFPHP</title>
      <link>http://snippets.dzone.com/posts/show/3367</link>
      <description>This code should be used to perform remoting with Flash 8 using ActionScript 2.&lt;br /&gt;&lt;br /&gt;&lt;code&gt;&lt;br /&gt;// remoting&lt;br /&gt;import mx.remoting.Service;&lt;br /&gt;import mx.remoting.PendingCall;&lt;br /&gt;import mx.rpc.RelayResponder;&lt;br /&gt;import mx.remoting.debug.NetDebug;&lt;br /&gt;&lt;br /&gt;NetDebug.initialize();&lt;br /&gt;&lt;br /&gt;var myResponder:RelayResponder = new RelayResponder(this,"say_Result","say_Fault");&lt;br /&gt;var siteCFC:Service = new Service("http://127.0.0.1/flashservices/gateway.php",null,"HelloWorld",null,myResponder);&lt;br /&gt;var temp_pc:PendingCall = siteCFC.say("Hola chicos!");&lt;br /&gt;&lt;br /&gt;function say_Result(re){&lt;br /&gt;	trace(re.result);&lt;br /&gt;}&lt;br /&gt;function say_Fault(result){&lt;br /&gt;	trace("error!");&lt;br /&gt;}&lt;br /&gt;&lt;/code&gt;</description>
      <pubDate>Thu, 25 Jan 2007 21:42:38 GMT</pubDate>
      <guid>http://snippets.dzone.com/posts/show/3367</guid>
      <author>alexwilliams (Alex Williams)</author>
    </item>
    <item>
      <title>PHP: Connecting Flash to a Database (remoting)</title>
      <link>http://snippets.dzone.com/posts/show/3213</link>
      <description>There are many ways to do this.&lt;br /&gt;&lt;br /&gt;Depending on the backend language you're using, whether PHP, ColdFusion or other... you'll need to create some components (CFC's for ColdFusion), (Classes for PHP)... these are referred to as "services"&lt;br /&gt;&lt;br /&gt;Then you'll need to connect Flash to a remoting gateway (I use AMFPHP for PHP: www.amfphp.org).&lt;br /&gt;&lt;br /&gt;Either way, you'll need NetServices.as from Flash MX Remoting, call a gateway and retrieving a list of functions from your classes/components/services.&lt;br /&gt;&lt;br /&gt;Enough with the theory, here's how to do it with PHP:&lt;br /&gt;&lt;code&gt;&lt;br /&gt;/* /flashservices/services/Catalog.php */&lt;br /&gt;class Catalog {&lt;br /&gt;        var $products_array = array();&lt;br /&gt;&lt;br /&gt;// Constructor: Contains the list of methods available to the gateway&lt;br /&gt;function Catalog() {&lt;br /&gt;	$this-&gt;methodTable = array (&lt;br /&gt;		"getProducts" =&gt; array (&lt;br /&gt;			"description" =&gt; "Get list of products",&lt;br /&gt;			"access" =&gt; "remote",&lt;br /&gt;			"arguments" =&gt; "" // arguments could be optional, not tested&lt;br /&gt;		)&lt;br /&gt;	); // end methodTable&lt;br /&gt;}&lt;br /&gt;&lt;br /&gt;function getProducts() {	&lt;br /&gt;	// your code goes here&lt;br /&gt;&lt;br /&gt;	return $this-&gt;products_array;&lt;br /&gt;}&lt;br /&gt;}&lt;br /&gt;&lt;/code&gt;&lt;br /&gt;&lt;br /&gt;!!!!!!!!! The code below is now deprecated !!!!!!!!&lt;br /&gt;---- see my other snippet to do this in Flash 8 ----&lt;br /&gt;&lt;br /&gt;Flash ActionScript (PHP Gateway):&lt;br /&gt;&lt;code&gt;&lt;br /&gt;#include "NetServices.as"&lt;br /&gt;NetServices.setDefaultGatewayUrl("http://yourserver.com/flashservices/gateway.php");&lt;br /&gt;gw = NetServices.createGatewayConnection();&lt;br /&gt;CatalogREMOTE = gw.getService("Catalog", this);&lt;br /&gt;CatalogREMOTE.getProducts();&lt;br /&gt;&lt;br /&gt;getProducts_Result = function(result) {&lt;br /&gt;	_root.products_results = result;&lt;br /&gt;}&lt;br /&gt;&lt;/code&gt;&lt;br /&gt;&lt;br /&gt;You parse the _root.products_results array however you want :D&lt;br /&gt;</description>
      <pubDate>Thu, 28 Dec 2006 00:34:50 GMT</pubDate>
      <guid>http://snippets.dzone.com/posts/show/3213</guid>
      <author>alexwilliams (Alex Williams)</author>
    </item>
  </channel>
</rss>
