Update 2.23.2003 - For anyone that is just reading over this thread. There is a new more refined and complete Flash Remoting toolkit for PHP at
http://www.amfphp.org, this should be used in the future. The following is some really great background info and simple working examples (Must Read). Also it is recommended for anyone interested to sign up for the AMF-PHP mailing list to follow along with the development and ask questions.
New 1.23.2003 - A new message board has been added for future questions, discussions, and news on Flash Remoting with PHP. The link is as follows:
http://www.flash-db.com/Board/index.php?board=24 Please post any questions on this Board.
New 27.03.2006 -Just find this thread, the one at the very beginning of the amfphp project when Musicman post the amfphp base class. It's outdated of course, but I sticky it anyway(jorge)
I've been playing around with
Musicman's amazing php script which allows you to pass array's/objects directly to and from a PHP script and a Flash movie. I was hoping to open up a discussion on this topic!
For anyone not familiar with this please read over the great article by Musicman here:
http://www.flash-db.com/Board/index.php?board=19;action=display;threadid=3062 The last part of that thread (amf / flash remoting).
New: - Flash remoting with Web services:
http://www.flash-db.com/Board/index.php?board=19;action=display;threadid=3190What this allows you to do is pass arrays (multidimensional array's!) from a PHP script to a flash movie. I'm sure that anyone that tries this out will find it
extremely useful...
This thread is dedicated to seeing how much we can actually do with this concept and coming up with new use's.
AMF is short for Actionscript Message format. This is a format that Macromedia developed for their Flash remoting products. It's a binary format that allows you to pass array's/objects to and from a server.
I'll start from the beginning for anyone that may not be familiar.
To get this up and running follow the below steps, this will help you become familiar with what we are talking about so we can have a better discussion.
1: Create a flash movie called "amftest". (doesn't have to be called that but we'll refer to it by that name).
On the first frame of the movie place the following code:
var nc = new NetConnection();
nc.connect("amfclient.php");
var reply = {};
reply.onResult = function(result) {
_root.myresult = "result is "+result[ 0 ];
};
data1 = "test";
data2 = "test2";
nc.call('script1', reply, data1, data2); // here data1 and data2 are arbitrary flash data items
We will be dealing a lot with the line in
Red so pay special attention to that for the demonstration.
2: In the flash movie create a text field and give it a variable (Var:) name of 'myresult'. Normally we could just put a trace command in their - but since not everyone has php installed on there desktop (and only their server) we'll do it this way.
3: Create a PHP script with the following code;
<?
include "amfdata.php"; // parse request
$request = new amfdata(); // parse request
switch($request->fn)
{
case 'script1':
$sample = array("newTest1"=>"multiTest1","newTest2"=>"someOtherValue");
$data = array(0=>23.45, 1=>5.3, "test"=>"jeffRemote", "multiArray"=>$sample);
$request->sendresult($data);
}
?>
Call the above script "amfclient.php". Place this in a directory on your server. Make sure it's the same directory where your flash movie "amftest.swf" is located.
Finally - download the "amfdata.php" script from
http://www.fontimages.org.uk/flash/amfdata_php.htmlCopy and paste the code from that file and create a PHP script called "amfdata.php". This is basically your Remoting server. It will handle
Place that in the same directory as the others.
That's it! Now where ready to start experimenting with some really cool amf features.
To start experimenting, Test out the Flash movie you just created in a browser. You should see the following appear in the text field called 'myresult' (that you created earlier):
result is 23.45That's a very basic example - but should get you started. Next we'll try something a bit more complicated.
- Find the following lines in the 'amfclient.php' script.
$sample = array("newTest1"=>"multiTest1","newTest2"=>"someOtherValue");
$data = array(0=>23.45, 1=>5.3, "test"=>"jeffRemote", "multiArray"=>$sample);This is a basic PHP array. We made it a bit more interesting by using an Array inside an array (to test the limits of the script). (You can obviously change these array's around to anything you want).
In the Flash movie change the line in
Red to:
_root.myresult = "result is "+result.test;This will produce the result:
result is jeffRemote. This is just a different way of accessing an array propery in Flash (ecmascript). Basically were using the (index) key from the php array and accessing it in Flash ("test"=>"jeffRemote"). This can be a really useful way of passing information in Flash.
Now we get a bit more complicated, change the line in
Red to:
_root.myresult = "result is "+result.multiArray.newTest2;This will produce the result:
result is someOtherValue. Wow now that's useful. In this case since our PHP array's is using strings as the index keys - we can use the same index key in Flash to access the multi-dimensional array value from a php array inside of Flash. - (result.multiArray.newTest2) - multiArray is the index in the first array, newTest2 is the index of the second array. The value of that cell is - someOtherValue.
- And that's about it. Hopefully that wasn't to complicated. Once you start playing around with this you'll find it really useful - I know I will.
Please post any comments, questions, or code snipets so we can all become more familiar with this. This is really new to everyone - so anything will be possible.
Extra special Thanks to
Musicman (Wolfgang) for writing the Code and explaining how this works.