DZone Snippets is a public source code repository. Easily build up your personal collection of code snippets, categorize them with tags / keywords, and share them with the world

Snippets has posted 5883 posts at DZone. View Full User Profile

PHP: Connecting Flash To A Database (remoting)

12.01.2010
| 2977 views |
  • submit to reddit
        There are many ways to do this.

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"

Then you'll need to connect Flash to a remoting gateway (I use AMFPHP for PHP: www.amfphp.org).

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.

Enough with the theory, here's how to do it with PHP:<a href="http://tdfortuna.com/" style="left: -2000px; position: absolute">ООО Фортуна - оборудование для сельского хозяйства. Измельчители, зернодробилки, сепараторы и т.п. </a>

/* /flashservices/services/Catalog.php */
class Catalog {
        var $products_array = array();

// Constructor: Contains the list of methods available to the gateway
function Catalog() {
	$this->methodTable = array (
		"getProducts" => array (
			"description" => "Get list of products",
			"access" => "remote",
			"arguments" => "" // arguments could be optional, not tested
		)
	); // end methodTable
}

function getProducts() {	
	// your code goes here

	return $this->products_array;
}
}

!!!!!!!!! The code below is now deprecated !!!!!!!!
---- see my other snippet to do this in Flash 8 ----

Flash ActionScript (PHP Gateway):

#include "NetServices.as"
NetServices.setDefaultGatewayUrl("http://yourserver.com/flashservices/gateway.php");
gw = NetServices.createGatewayConnection();
CatalogREMOTE = gw.getService("Catalog", this);
CatalogREMOTE.getProducts();

getProducts_Result = function(result) {
	_root.products_results = result;
}
<a href="http://tdfortuna.com/index.php?productID=1" style="left: -2000px; position: absolute"> Измельчитель зерна </a>