1. Summary
In this tutorial we will learn something about the usage of the remoting connector, the DataHolder component and how to bind data using a custom formatter class to populate a listbox component.
First the finished example:
Download the source file for this tutorial: dataHolder.zip
2. create the php class
in my /flashservices directory (which is placed in the site root) I've defined the gateway.php files which allows me to call from Flash the remoting classes. If you haven't flash remoting AMFPHP installed yet, download it first from: http://sourceforge.net/projects/amfphp
Once installed create the gateway.php file inside your flashservices directory (as explained also in the documentation of amfphp) and write this php code inside:
<?php
include("./app/Gateway.php");
$gateway = new Gateway();
$gateway->setBaseClassPath(realpath("services/") . "/");
$gateway->service();
?>
Now, inside your {siteroot}/flashservices/services/ directory create a new directory "test" with inside new php file called testClass.php with this code inside:
<?php
class TestClass {
function TestClass() {
$this->methodTable = array(
"echoArray" => array(
"description" => "Return an array",
"access" => "remote",
"arguments" => array("")
)
);
}
function echoArray(){
$main = array();
array_push($main, array('code' => '001', 'description' => "Alessandro"));
array_push($main, array('code' => '002', 'description' => "Davide"));
array_push($main, array('code' => '003', 'description' => "Pietro"));
array_push($main, array('code' => '004', 'description' => "Mustafa"));
array_push($main, array('code' => '005', 'description' => "Jason"));
array_push($main, array('code' => '006', 'description' => "Enrico"));
array_push($main, array('code' => '007', 'description' => "Federico"));
array_push($main, array('code' => '008', 'description' => "Jonas"));
array_push($main, array('code' => '009', 'description' => "Another guy"));
array_push($main, array('code' => '010', 'description' => "a beautiful girl"));
array_push($main, array('code' => '011', 'description' => "two beautiful girls"));
array_push($main, array('code' => '012', 'description' => "more is better :)"));
return $main;
}
}
?>
In this way we have declared just one method "echoArray" which returns an array of custom Array (flash will see this array as an array of objects)
3. Setup Flash MX 2004 UI
For this tutorial I used the following components:
- Remoting Connector (instance name "NS" )
- DataHolder (instance name "myHolder")
- List (instance name "myListBox")
- TextArea (instance name "myArea")
