views:

43

answers:

3

Hi guys, I am trying to use AMF PHP to pass variables to a flash file, thus far I cannot see anything wrong with my code, but I have very little experience with creating classes, so here it goes, here is my code,

index.php:

<?php
include "amfphp/services/flashMe.php";

$session = true;

if ($session == true) {
 $uid = '12345';


  $thing = new flashMe;
  $thing->push($uid);

} else {

 //login

}

?>

flashMe.php:

<?php
class flashMe {

 public function __construct() {

 }

 public function push($one)
 {   
    return $one;//sends the uid to the flash file?
 }

}
?>

Flash is looking for the flashMe class and the push method within that class, but I keep getting null variables in my flash file when I run it, is there something wrong with this code?

Thanx in advance!

A: 

You missed the parenthesis after new flashMe

$thing = new flashMe(); $thing->push($uid);

bPizzi
Btw, __construct() is not needed if it's empty.
bPizzi
Cool, thanx will give it a go. But is it possible to achieve what I am trying? Because I have had little success with sending variables to amf php and having flash receive it.
A: 

Amfphp or Zend AMF only allow you to call public methods on a remote class that is exposed by your gateway. You example is not a class and therefore no remote method can be called. This looks more like something that you would do with an http post.

http://framework.zend.com/manual/en/zend.amf.server.html

Wade Arnold
+1  A: 

Your index.php file is unnecessary.

Your second file is incomplete. Here is the example from the docs for their "hello world" class file:

<?php
class HelloWorld
{
    function HelloWorld()
    {
        $this->methodTable = array
        (
            "say" => array
            (
                "access" => "remote",
                "description" => "Pings back a message"
            )
        );
    }

    function say($sMessage)
    {
        return 'You said: ' . $sMessage;
    }
}
?>

This file should be saved as "HelloWorld" matching the "class HelloWorld" you have named in the php file (you did this part right with FlashMe).

The example file in the docs for the Flash piece (in actionscript) is here:

import mx.remoting.*;
import mx.rpc.*;
import mx.remoting.debug.NetDebug;

var gatewayUrl:String = "http://localhost/flashservices/gateway.php"

NetDebug.initialize();
var _service:Service = new Service(gatewayUrl, null, 'HelloWorld', null , null);
var pc:PendingCall = _service.say("Hello world!");
pc.responder = new RelayResponder(this, "handleResult", "handleError");

function handleResult(re:ResultEvent)
{
    trace('The result is: ' + re.result);
}

function handleError(fe:FaultEvent)
{
    trace('There has been an error');
}

The gateway URL should go to wherever your services can be reached. I'm sure if you try a few you'll find the right one. The neat thing about amfphp is that it allows you to also test your services out before you try implementing them in the gateway (if you go to the URL in your browser).

I'm pretty new to AMFPHP as well, but I've found the docs to be extraordinarily useful. If you need more help on classes, you can find more info on the PHP docs page.

Organiccat