Flash Communication and Flash Remoting login
Folder structure
The expected folder structure is:
Web structure:
root (root folder of your web server)
flashservices (amfphp library)
login (main folder)
login.htm
login.swf
gateway.php
services (services folder)
login.php
inc_sql.php
FlashCom structure
<Flashcom installation folder>
applications (in this folder are all your FlashCom app's)
login (folder for our app)
main.asc
If you unzip the examples files, you will see the Web structure and inside the login folder, main.asc. So you need to create the login folder inside your FlashCom applications folder and move main.asc there.
The database
We will use a table with only one row in the Users table:
CREATE TABLE users (
PkUser int(11) NOT NULL auto_increment,
Username varchar(255) NOT NULL default '',
Password varchar(255) NOT NULL default '',
PRIMARY KEY (PkUser)
) TYPE=MyISAM;
INSERT INTO users VALUES (1, 'test', 'test');
You can run install.php to create the database and the table. If you decide to setup the example without install.php, you can use users.sql file who holds all the necessary SQL (but you need to create the database first)
The Remoting Class: authenticate.php
We will use a Remoting class named login in a folder named services, with only one method: authenticate. Again, if you don't know how to setup an amfphp Remoting class, read Hello World Remoting. Here's our product class:
<?php
include_once("inc_sql.php");
class login{
var $dbhost = HOSTNAME;
var $dbname = DATABASE;
var $dbuser = USERNAME;
var $dbpass = PASSWORD;
function login(){
$this->methodTable = array(
"authenticate" => array(
"description" => "Check for a username and password",
"access" => "remote", // available values are private, public, remote
"arguments" => array ("username", "password")
)
);
// Initialize db connection
$this->conn = mysql_pconnect($this->dbhost, $this->dbuser, $this->dbpass);
mysql_select_db ($this->dbname);
}
function authenticate($username, $password){
$result = mysql_query("Select PkUser from users where Username='$username' and Password='$password'");
if(mysql_num_rows($result)>0) return true;
else return false;
}
}
?>
The authenticate method simply query the database passing the username and password the user enters in the Flash movie. The inc_sql.php file holds all the necessary data to connect to the database (modify to match your own needs)
Also we need a gateway.
<?php
//default gateway
include "../flashservices/app/Gateway.php";
$gateway = new Gateway();
$gateway->setBaseClassPath("./services/");
$gateway->service();
?>
If you change the folder structure, you need to change gateway.php to match
your needs.
Ok, let's move to the FlashCom part

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