Using the remoting connector components in Flash MX Professional 2004: Editing a table
Creating the database table
First create a table in mysql with the following structure
CREATE TABLE list ( PkProduct int(11) NOT NULL auto_increment, Name varchar(255) NOT NULL default '', Weight varchar(10) NOT NULL default '', Price varchar(10) NOT NULL default '', PRIMARY KEY (PkProduct) ) TYPE=MyISAM;
You can run the install.php file to create the database and the table. If you decide to setup the examle without install.php, you can use the list.sql file which holds all necessary SQL, however you will need to create the database first.
The Remoting Class: products.php
We will be using a remoting class named products that is located in a folder named services. This class has two methods: getItems and setItems. Again, if you do not know how to setup a amfphp remoting class, read over Hello World Remoting.
Here's our product class:
<?php
include_once("inc_sql.php");
class products{
var $dbhost = HOSTNAME;
var $dbname = DATABASE;
var $dbuser = USERNAME;
var $dbpass = PASSWORD;
function products(){
$this->methodTable = array(
"getItems" => array(
"description" => "Returns products table",
"access" => "remote" // available values are private, public, remote
//"arguments" => array ("message")
),
"setItems" => array(
"description" => "Echoes the passed argument back to Flash (no need to set the return type)",
"access" => "remote", // available values are private, public, remote
"arguments" => array ("rs")
)
);
// Initialize db connection
$this->conn = mysql_pconnect($this->dbhost, $this->dbuser, $this->dbpass);
mysql_select_db ($this->dbname);
}
function getItems() {
return mysql_query("select * from list");
}
function setItems($rs){
$error = false;
for($i=0; $i<sizeof($rs); $i++){
$result = mysql_query("replace into list values('".$rs[$i][PkProduct]."', '".$rs[$i][Name]."', '".$rs[$i][Weigth]."', '".$rs[$i][Price]."')");
if(!result) $error = true;
}
if(!$error) return "Ok"; else return "Error";
}
}
?>
The first method, getItems, returns all rows in our table. The second, setItems, updates all the rows with a replace statement. This is not the best method, since any change in any row will force the entire table to update - but this is the simplest. In a large database, you should edit records one at a time, or send just the modified records tracking changes through the modelchanged event in the dataset (we will add this in the near future).
Next we need to create the gateway
<?php
//default gateway
include "../flashservices/app/Gateway.php";
$gateway = new Gateway();
$gateway->setBaseClassPath("./services/");
$gateway->service();
?>
Here we assume that the flashservices folder is above the current folder, and that the services folder is located below where this script resides.
Let's move to the Flash Part
The Remoting Connector
![]()
We are going to be using the remoting connector by Justin Watkins, one of the amfphp developers. It is not included in the standard data components that come with Flash MX Pro, so you will need to download it from amfphp.org/components/. It now comes packaged as an mxp file, which means you can use the extenstion manager to install it.
Once installed, you will have a new Category in the components panels called Remoting Components here you can find the Remoting Connector. So let's begin by creating a new flash document and adding a couple of layers to it. One for code, the other for the components. Drag a remoting connector on the left side of the stage and give it an instance name of con1_con, select it and use the property inspector to add a couple of parameters:
gatewayUrl -> gateway.php method -> getItems service -> products
The first connector will call the getItems method and return all items inside the products table. We will also need another remoting connector to call the setItems method to update the table with modified data. Add this by dragging another remoting connector onto the stage and giving it an instance name of con2_con and fill the parameters with the same gatewayUrl and service. For the method enter setItems.
Now that all of the remoting connectors are set up, lets move onto the dataset.

5 most recent
Flash button as Flex icon
Tree menu
Flash Spell Checker
Flash Remoting Library
MX 2004 Chart/Poll
Articles