hide side navigation
    5 most recent
    Web Services
    Library's
    Component's
    Applications
    Articles
  Flash button as Flex icon  Flex form by email  Hello Remoting with AS3  AS3 Saving data from Flash  AS3 Loading data into Flash  Fire Effect  Contact form  Dragable buttons  Hello World with openamf  Loading helper classes  Upload with Flash 8  Transitions effects  Snapshot with Flash 8  Hello World Remoting AS2  Flash AS2 Remoting Connector  Saving data from Flash  Loading data into Flash  FlashCom & Remoting login  Cell Renderer API  Editing a table using remoting components  Flash MX2004 web service classes  Browsing a catalog  amfphp Documentation  Hello World Remoting  Online Store with AMFPHP  Flash clients for Web Services  Web Service Walk Though with NuSoap  Popup windows in flash with javascript  Installing Apache/PHP  MoreOver News Feeds  Load Edit Save Text Files via CGI  Save Movie Clip Postion via PHP and MySQL
Current Page (1) Next Page >>  View Article Example >> 1 | 2

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.

Current Page (1) Next Page >> 1 | 2