PDA

View Full Version : Sorry....


butterbur
03-12-2003, 06:12 PM
I saw a virgin topic and just had to go for it.
Could someone please give a simple explination of what flash remoting could be used for.
Ta.

Prozail
03-12-2003, 06:45 PM
I quote Macromedia :) (from their website):

"Macromedia Flash Remoting MX provides the connection between Macromedia Flash and your web application server, making it fast and easy to create Rich Internet Applications. With its powerful yet simple programming model, you can easily integrate rich Macromedia Flash content with applications built using Macromedia ColdFusion MX, Microsoft .NET, Java, and SOAP-based web services."

I havn't been able to try it out yet.. downloaded the demo today, as i will prob. be involved in a project that require it....

reading manual now.....

:)

/Prozail

freddycodes
03-12-2003, 07:22 PM
Tons of things

Here is an example
http://www.irq11.com/~louie/webService/irecipe.html

A PHP class lives on the server. Its function is to query a recipe database via a web service sitting in some other location. Remoting allows me to pass data to PHP and have the data type automatically converted to a PHP data type, run the functions on the server and pass back the data automatically ocnverting it from PHP data types back to Flash data types. All with about 5 lines of code in flash.

butterbur
03-12-2003, 08:29 PM
I'm sorry to be dense but what is the difference between what you're describing and using sendAndLoad().
If this is a case of just go and read www.whatever then please say.
Thanks for taking the time, I'm keen but somewhat mentally challenged :D

freddycodes
03-12-2003, 08:44 PM
The difference is with sendAndLoad the PHP is responsible for getting the data from Flash figuring out what to do with it and doing it then getting the response into some format flash can understand and sending back. On the other flash must figure out what to do with it and create a flash data type to store the result. With remoting you can call the functions in the php class if you were in PHP passing the arguments. I guess I am having a hard time putting this into terms you can understand. Does what is below make more sense?

The PHP

<?php

class people extends PHPRemoting
{
function people() {
$this->db = mysql_connect(DBHOST,DBUSER,DBPASS);
mysql_select_db(DBNAME);
$this->PHPRemoting();
}

function getPersonById($id) {
return mysql_query("SELECT * from test WHERE id = ".$id);
}

function getCityList()
{
$sql = "SELECT DISTINCT City from test ORDER by City";
return mysql_query($sql);
}
function updatePerson($obj)
{
$sql = "UPDATE test set ";
$a = array();
foreach($obj as $key => $val) {
if ($key != 'id' && $key != '__ID__') {
$a[] = "$key = '".addslashes($val)."'";
}
}
$sql .= implode(",", $a);
$sql .= " WHERE id = ".$obj['id'];
$q = mysql_query($sql);
if(mysql_affected_rows())
{
return "Record updated successfully";

}
else
{
return "Error updating record";
}
}

function getPeopleByCity($City, $fields) {
$sql = "SELECT ";
if(!is_array($fields)) {
$sql .= "*";
}
else {
$sql .= implode(",", $fields);
}
$sql .= " from test WHERE City = '".$City['City']."'";
return mysql_query($sql);
}

}
?>


The Actionscript


<?php

class people extends PHPRemoting
{
function people() {
$this->db = mysql_connect(DBHOST,DBUSER,DBPASS);
mysql_select_db(DBNAME);
$this->PHPRemoting();
}

function getPersonById($id) {
return mysql_query("SELECT * from test WHERE id = ".$id);
}

function getCityList()
{
$sql = "SELECT DISTINCT City from test ORDER by City";
return mysql_query($sql);
}
function updatePerson($obj)
{
$sql = "UPDATE test set ";
$a = array();
foreach($obj as $key => $val) {
if ($key != 'id' && $key != '__ID__') {
$a[] = "$key = '".addslashes($val)."'";
}
}
$sql .= implode(",", $a);
$sql .= " WHERE id = ".$obj['id'];
$q = mysql_query($sql);
if(mysql_affected_rows())
{
return "Record updated successfully";

}
else
{
return "Error updating record";
}
}

function getPeopleByCity($City, $fields) {
$sql = "SELECT ";
if(!is_array($fields)) {
$sql .= "*";
}
else {
$sql .= implode(",", $fields);
}
$sql .= " from test WHERE City = '".$City['City']."'";
return mysql_query($sql);
}

}
?>

butterbur
03-12-2003, 09:02 PM
Dear freddycodes,
I think I'm beginning to see a chink of light however I would like to see the actionscript. Sorry but I think you pasted the same bit.
If the light bulb does go on then you will have done your good deed for the day:)

freddycodes
03-12-2003, 09:20 PM
Right sorry


#include "NetServices.as"
#include "NetDebug.as"
#include "DataGlue.as"
init = false;
if(defaultGateway == undefined) defaultGateway = "http://freddy/amf/freddyServer.php";
function connect() {
if(init == false) {
init = true;
NetServices.setDefaultGatewayURL(defaultGateway);
conn = NetServices.createGatewayConnection();
myservice = conn.getService("people", this);
loadCities();
}
}
connect();
function loadCities() {
myservice.getCityList();
}

Jesse
03-13-2003, 01:30 AM
Freddy man, quit bursting my bubble! My tutorial isn't even out yet and you're outdoing it! :)
From my upcoming tute:
What is Flash Remoting?
Flash Remoting is a Flash MX specific feature which allows you to execute Remote Procedural Calls (RPCs) via Flash MX and transfer serialized, type-persistent objects directly between the server and a Flash MX client.
In more simple terms, Flash Remoting allows your Flash MX movie to exchanged typed data directly with a server-side language, allowing for increased and more easy integration between the front-end and backend of your site. For example, you can send an array from your server-side language into Flash as an array, instead of as an XML object or a String representing an array (which you process within Flash to turn it back into an actual, Flash readable array).
The major use for Flash Remoting is in creating Rich Internet Applications (RIAs). In other words, using Flash not just as an animation tool, or even a jazzy HTML interface, but as the GUI and Client for a full-scale, service providing, Internet application.

What Flash MX Remoting isn’t.
Flash MX Remoting is not the same as Flash Communication server, which is also receiving a lot of attention now (February, 2003). Communication Server is the new Flash technology which allows for video and audio streaming and recording, Server Side ActionScript, Remote Shared Objects and “Data Push”, among other things. Both Flash MX Remoting and Flash Communication Server are going to go a long way to making Flash an even more dominant player in the market than it already is, but it’s important not to get the two confused.

What is PHP Remoting?
Macromedia designed Flash MX Remoting as a direct link between Flash MX and Cold Fusion MX. The protocol used in Flash MX Remoting is called ActionScript Message Format (AMF) and is (at the time of writing) a proprietary format (non open-source). After the release of Flash MX Remoting (for Cold Fusion) certain open-source developers who favored PHP as their server-side language of choice over Cold Fusion, decided to investigate the binary AMF format and create their own Gateway (or ‘translator’) so that Flash MX Remoting could be integrated with PHP in a similar manner to Cold Fusion. The result is the AMFPHP project. A PERL implementation is also available (http://www.simonf.com/flap/) based on the PHP project.

Why use Remoting?
Remoting will drastically reduce the amount of work you have to do when exchanging large volumes of data between Flash and a server because it allows for direct exchange of Objects; meaning you don’t have to break down delimited strings or pass lengthy XML.
Further, the AMF format used in Remoting is binary, so it is considerably less verbose than XML and XML-based methods such as WDDX serialization. That is not to say that XML isn’t great – keep in mind that a binary AMF file, unlike an XML file, is not at all human-readable; one of the key pros for using XML.
And yes, it's going to be a LONG tutorial. It's about 5,000 words already and not yet finished :)

freddycodes
03-13-2003, 03:14 AM
Come one now ;) , thats everything I wanted to say but couldn't translate into words from my over-stressed code-filled brain.

Jesse
03-21-2003, 11:17 AM
Further to this and subject to some adaptation which will doubltessly be needed to improve it, my PHP Remoting tutorial is now online via http://www.actionscript.org/tutorials/intermediate/PHP_Remoting/index.shtml

Enjoy!

CyanBlue
03-21-2003, 12:30 PM
WoW... This stuff isn't easy... :( But then, what's easy??? Oh, there was one... trace() function... That's it... :)

Thank you Jesse... I will try to wrap up my current project as soon as possible and get right on to it... :DRequirements: Flash MX, Remoting Components (Free), PHPAMF Gateway (Free), Compatible WebhostI think that is a typo, PHPAMF, and it should be AMFPHP, right???

Jesse
03-22-2003, 03:38 AM
True, I'll fix it. Cheers :)

designlevel2
03-24-2004, 02:55 PM
Can anyone shed some light on populating an array locally in flash using remoting and CFC? I'm loading images, that need to preload. If populate the array statically everything is fine but I can not populate the array from the database. I know im missing something stupid.

Thanks in advance.