PDA

View Full Version : Problems with Flash Remoting with AMFPHP


powerobject
07-04-2005, 07:36 AM
I tried everything to setup the service using AMFPHP 1.0 and the following article that covers AMFPHP v0.5 but could not succeed:

http://www.macromedia.com/devnet/mx/flash/articles/amfphp.html

The new version of AMFPHP v1 does not have the examples folder, several files, classes/functions that the above article refers to. Have the file/class/function names changed in v1 of AMFPHP? Could someone give me instructions on setting up remoting with Flash MX Professional 2004?

Thanks much,

---
PowerObject!

hobbis
07-04-2005, 10:27 AM
Download and unzip the Beta 1.0 vesion of AMFPHP. Put the contents of the zip file in your website root so the path structure is like this:

root/flashservices

There's a gateway file in the 'flashservices' folder. Opn this and set the variables:

//Set the path to your services folder. I've moved mine up one level alongside flashservices.
$gateway->setBaseClassPath(realpath("../services/") . "/");

//set your Charset handler. There is a typo in the zip file. Make sure it's this if you are running English charset
$gateway->setCharsetHandler("none", "ISO-8859-1", "ISO-8859-1", "ISO-8859-1");

Save it. That's it for that file.

In your services folder, create a new file and call it say: HelloWorld.php
The name of the file is important. This will be the same name as my class contained inside it.

Copy and paste this:


<?php
class HelloWorld
{
function HelloWorld() {
$this->methodTable = array(

"displayHello" => array(
"description" => "Gets user data",
"access" => "remote",
"arguments" => array ()
)
);
}

function displayHello() {
return "Hello World";
}
}
?>


That's the AMFPHP side of things. Now the flash side.

Make sure you have downloaded and installed the Flash Remoting as2.0 source code library. you can install the components at a later date when you have got the hang of things. For now, download the library here:

On this page: Flash Remoting downloads (http://www.macromedia.com/software/flashremoting/downloads/components/#flr_as2)

The file is called:flashremoting_comp_sourcecode.zip

Unzip this folder. This is the tricky bit. The folder contains the classes as they should appear in your Flash MX 2004 installation. so the inital folder is 'mx', therefore anything in this will correspond to your mx folder in your installation on C drive or whatever. Now, inside the mx folder are the folders:

mx/data
mx/rpc
mx/remoting
mx/services
mx/utils

If these folders do not exist in your own mx folder, just copy the whole folder across (such as the remoting folder), if they do (such as utils), copy the CONTENTS of the folder into the equivalent folder on your MX2004 installation.

Now, in flash, create an AS2.0 class file that uses all of this new setup:


import mx.remoting.*;
import mx.rpc.FaultEvent;
import mx.rpc.ResultEvent;
import mx.rpc.RelayResponder;
import mx.services.Log;
import mx.remoting.debug.NetDebug;

class HelloWorld {

//Service properties
private var m_service:Service;
private var m_pc:PendingCall;
private var m_logger:Log;

public function HelloWorld() {
NetDebug.initialize()
m_logger = new Log(Log.DEBUG, "myLogger");
m_service = new Service("http://www.locationofyourgatewayfile.com/flashservices/gateway.php", m_logger, "HelloWorld", null, null);
m_pc = m_service.displayHello();
m_pc.responder = new RelayResponder(this , "displayHello_Result", "displayHello_Fault");
}


private function displayHello_Result(re:Object) {
trace(re.result) ;// displays Hello World
}

private function displayHello_Fault(fe:Object) {
trace("There's a been a problem")
}
}



Now run the file and if all is well, you should see the trace Hello World. Let me know how it goes, I will help you set this up. I've written this off the top of my head so forgive me if I have made a typo somewhere.

powerobject
07-05-2005, 11:02 PM
Thank you very much for the detailed reply. I'll try it out in a day or two and let you know the results.

Another quick question:
If I use Flash Remoting, do the end users need to download and install any Flash Remoting (objects/components/runtime) in order to run the SWFs? Or, is the Flash Player browser plugin adequate to run them? Does Flash embed all the remoting functionality into SWFs so the Flash Player plugin is adequate to run them? Is AMFPHP the best one out there for remoting Flash?

Great day,

---
PowerObject!

hobbis
07-07-2005, 08:22 AM
You don't have to worry about the plugin. The Remoting libraries are imported at runtime and are included in your swf file. I find AMFPHP easy to use. There is a good site which specialises in AMFPHP here:

http://www.flash-db.com and they have a good forum on the topic. Also check out the wiki on the AMFPHP.org site too. They have some examples in AS2.0.

Let me know how you get on.

powerobject
07-13-2005, 09:15 PM
I've tried your script but it did not work for some reason. Could be a minor typo but it did not show any errors or alerts, either.

I bought this article:

Using Flash Remoting with PHP: AMFPHP (By: Joey Lott)
http://www.communitymx.com/abstract.cfm?cid=B74BC

and will re-try connecting.

Is it a good idea to base an entire website on Flash without HTML? What if Flash plugin gets screwed up down the road by Macromedia for some reason taking our website (production) down?

Thanks,

PowerObject!