views:

62

answers:

5

Hi guys, is it possible to call a PHP function from flash and have it execute right away?

If so how could I go about doing that, because I am trying to call a PHP function that will update a users facebook status, but thus far I have been unsuccessful, so I am kind of at the end f my rope.

Any help would be appreciated, thanx!

+2  A: 

Have a look at AMF PHP!

Bogdan Constantinescu
Would cURL be an option?
AMF PHP doesn't work with cURL. In php you just create a service using AMF documentation and in Flash(actionscript) a Service (you can see some examples in the AMF documentation).
Bogdan Constantinescu
A: 

The way I would do it is in the flash actionscript is call a javascript function using getURL("javascript:someFunction(var-1, var-2, var-n)") http://www.adobe.com/livedocs/flash/9.0/main/wwhelp/wwhimpl/common/html/wwhelp.htm?context=LiveDocs_Parts&file=00001180.html

That javascript function can then do an ajax request to a php script.

EDIT:

you could just post data directly without using AJAX:

var firstName:String = "Gus";
var lastName:String = "Richardson";
var age:Number = 92;
getURL("http://www.adobe.com", "_blank", "POST");

Brady
Would cURL be an option?
what I've given will allow flash to talk to your PHP. then for your PHP to talk to FB is another matter. try reading this post and it might give you help on updating facebook status from php. http://stackoverflow.com/questions/1016730/facebook-status-update-through-php
Brady
http://codesnippets.joyent.com/posts/show/1204some code for php to post to FB using cURL. Now just use $_POST variables from flash to that PHP script.
Brady
Thanx for the help!
Those examples are from the old api unfortunately, I have gotten it to work with the new graph api and cURL, thanx again!
A: 

Why you are not using a Flash API for Facebook: http://code.google.com/p/facebook-actionscript-api/ ?

Hippo
I am not doing the Flash side of things, I only do the PHP, so I don't really have controll over what the flash guys do, but I will recommend it, thanx!
You won't solve this problem without any usage of Flash / ActionScript... but in you case I would suggest to go for the AMF PHP thing....
Hippo
+1  A: 

Save the PHP function in facebookFunction.php and call it using a URLLoader.

var urlLoader:URLLoader = new URLLoader();
var data:URLVariables = new URLVariables();
//you can use dot syntax and/or [] syntax to add data.
data.user = "kiele";
data["someThingElse"] = "something else";
var req:URLRequest = new URLRequest("facebookFunction.php");
req.data = data;
urlLoader.load(req);

At the php side, you can read the values from the global get variable.

$user = $_GET["user"]
Amarghosh
+1  A: 

My idea would be something similar to the following:

function updateFBStatus(newStatus)
{
    // create two new instances of LoadVars, one to send and one to receive data
    var dataOut:LoadVars = new LoadVars();
    var dataIn:LoadVars = new LoadVars();

    // define what should happen when the response is received,
    // using 'this' to refer to dataIn and get data from it
    dataIn.onLoad = onReturn;

    dataOut["newStatus"] = newStatus;

    dataOut.sendAndLoad(serverURL+"setFBStatus.php", dataIn, "POST");
}

You then define the setFBStatus.php file on your server to read $_POST['newStatus'] and do whatever you would normally do in php to set the facebook status. That php file can optionally echo some return values in url request format (i.e, paramName1=param1&paramName2=param2&) for your onReturn function to read, if you need to.

death_au