AS3 FLASH REMOTING EXAMPLEMONDAY, MARCH 12 2007 @ 10:24 AMUsing remoting in AS3 is actually quite simple. Remoting calls are now made directly through NetConnection, so there's no need for Remoting classes or components, everything you need is readily available. Here is a quick example.
This is a wrapper class for NetConnection that makes sure we are using the right AMF encoding. The default is AMF3, which is not supported on AMFPHP versions lower than 2.0. So, we use AMF0 instead:
The next class is just a test that uses the previous class to make a call.
Given the following PHP class, the previous exercise could be easily adjusted to print "something and 2" to the Output panel. Just copy it to the 'services' folder of your AMFPHP installation, and replace "Class.method" with "Test.test" on the RemotingTest class. Test.php class Test { function __construct() { $this->methodTable = array( "test" => array( "description" => "Tests service", "access" => "remote" ) ); } function test($params) { return $params['arg1'] . " and " . $params['arg2']; } } ?> Archived under: PHP, Flash, ActionScript 3.0. | Permalink | google | del.icio.us | digg ![]() OSCAR TRELLESMARCH 12 2007 @ 10:42 AMI know, I know... I need some code highlighting thingy here.
DRUMARCH 14 2007 @ 04:15 PMCool!
My question is what do you do with the result? I'm tracing it out as an [Object object], which is only revealing a "serverinfo" property to me. Doesn't seem to be containing the actual return data. I tried the AS2 Remoting method of accessing the result property of the return object, but that's not defined (I'm using a remote service that I know works when using Remoting AS2-style). Thanks! OSCAR TRELLESMARCH 18 2007 @ 02:57 PMHey Dru, good question.
When the service returns an Object (not a String or a Boolean) it actually wraps it inside one a little more complex . The result you are expecting is actually a recorset containing a single object named 'serverInfo". If you dissect it, you will find it contains what you are looking for. This is its structure: totalCount: The total number of records in the recordset, as a Number initialData: The recordset data as an array cursor: 1 serviceName: If gateway implements pageable recordsets, the name of the service that retrieves further records in the recordset columnNames: The column names, as an array of strings. version: 1 id: A recordset id, only used if array is recordset is paged More info here: http://osflash.org/documentation/amf/recordset YAPRIL 2 2007 @ 02:16 AMytfrgh
TYLERAPRIL 17 2007 @ 05:23 PMok so I am returning a query result from a coldfuion cfc. In as2 i would use this to acces the data in the first recocrd :
"returned.result.items[0].aDBfield" how is it done in AS3? JOSHAPRIL 21 2007 @ 11:24 AMSo...what happened to PendingCall? Seemed like it was a much neater way to call a PHP class w/o having to pre-build an object for the params...
BAPRIL 23 2007 @ 03:31 AMh
DRUAPRIL 23 2007 @ 12:10 PMSo, I did a little digging, and in the process realized that the NetConnection class has always been the main class through which you do Remoting. The Remoting Components simply install a few extra classes to put a prettier face on the details. But in theory, you've always been able to do Remoting in a way similar to that outlined here, by using the NetConnection class. Oscar's RemotingService class seems like more or less the same kind of "wrapper" functionality you'd get from the Remoting classes installed by the Remoting Components download.
I'd be a bit surprised if Adobe didn't release an AS3 version of the Remoting Components, and allow us to keep using Remoting in a manner similar to the way we're used to with AS2. LEEAPRIL 24 2007 @ 10:35 AMI'm fairly new at this but I believe you have to deserialize the recordset, which could previously be done with the RDBMSResolver, which isn't implemented in Flash CS3.
JOSHAPRIL 27 2007 @ 03:35 PMI wrote a deserializer for a similar wrapper, along with an in-movie NetConnection Debugger, for anyone interested in using or improving it... get the package at http://www.joshstrike.com/strike_remoting.zip Cheers!
LEEMAY 2 2007 @ 11:32 AMMan, you really lose alot without the RDBMSResolver & DataSet classes. Any word on anyone rewriting and optimizing these classes for AS3?
LEEMAY 2 2007 @ 11:35 AMTo access your NetConnection result you need to loop through the result.serverInfo.initialData which is an assosiative array holding each database record. You need to tie each field to the proper result.serverInfo.columnNames, probably in the same loop function.
for (var prop in result.serverInfo.initialData) { trace(result.serverInfo.initialData[i]); } JOSHMAY 2 2007 @ 04:54 PMyeah, like I said, check out my little remoting package; it does all of that.
Cheers. LEEMAY 2 2007 @ 05:00 PMIve been meaning to do that. Have you created a DeltaPacket replacement? eg a class to manage changes to the DataSet that is created from the result?
TOMMYMAY 6 2007 @ 09:52 PMOk so what happened to the NetConnection Debugger when using AS3? Is there an alternative? If so, where can we get it? Thanks!
Tommy JOSHMAY 8 2007 @ 10:46 AMNo, nothing w/ DeltaPackets. If you do write that functionality in, please hit me up.
Tommy -- see the package. TOMMYMAY 8 2007 @ 07:00 PMExcuse my ignorance but what package are you referring to? Thanks,
Tommy TOMASZ STOCKIMAY 11 2007 @ 06:01 AMDRU, in file Test.php "" is missing at the beginning, then "trace" result is not "[Object object]" which its result onFault, but as in this example: "something and 2"
DRUMAY 11 2007 @ 11:01 AMThanks for the tip Tomasz, but I wasn't using the php file supplied here. I was using a known-to-be-working ColdFusion CFC from another project.
JUSOMAY 15 2007 @ 11:18 PMcould work this for web service?
JUSOMAY 15 2007 @ 11:20 PMHablas espa
JONASMAY 24 2007 @ 08:27 AMJuso asked how to use web services with AS3 now that the WebServiceConnector class doesn't exist
R DOLLARHIDEMAY 30 2007 @ 10:43 AMThanks for the AS3 example. Not too many good ones out there that I've seen. I'm attempting to wire up your example as shown except I'm using ASP.NET 2.0. Are you familiar with how I would structure my aspx and aspx.cs files to allow calls to the server using AS3?
NICOLASJUNE 3 2007 @ 10:37 AMr dollarhide:
hi! I just applied the above code (with AMF3), and am using AS3 to connect to an ASP.NET application. I'm not sure about the specifics because I am not a .NET developer in any way, but we are using Flourine as our remoting gateway between AS3 and .NET. It works well so far! http://fluorine.thesilentgroup.com/fluorine/ JJUNE 6 2007 @ 02:53 PMHow to call a Webservice method with Flash CS3 using AS3? Not possible is it?
KURT VAN SCHAEYBROECKJUNE 10 2007 @ 03:12 AMHello,
For two days now, I'm trying to install amfphp on my OSX with Flash CS3 and Flex Builder 2. Unfortunately, there are few clear install guies and tutorials out there for the newbies. Either OS, versions, language or details or forgotten, and so on. This one seems better than all the rest, so I thought I write the author. FIrst, I'm trying to call a php function from within Flash. And if that works I'll try it from within Flex. For now, I installed amfphp 1.2.6 on OSX 10.4 in the path /Library/Webserver/Documents/amfphp/ I managed to get a php "service" or .php class in there and I can see it with the browser form amfphp. But I can't get passed the netconnection thing. What do I have to do when workng with CS3? DO I need to install anything? And what do I have to put in the actionscript in my flash movie. I mean, what code do I use to actually connect? Hopefully someone can help me. Thanks in advance. DOMINIQUE PERETTIJUNE 18 2007 @ 02:16 PMKurt,
This is what you want to do to enable Flash Remoting in AS2 / CS3 : http://blog.vixiom.com/2007/04/17/actionscript-20-flash-remoting-with-flash-cs3/ KURT VAN SCHAEYBROECKJUNE 22 2007 @ 12:25 AMThx Dominique,
that's a helpful link. I figured it out now. |
![]() ARTICLES
BOOK REVIEWSSYNDICATIONFLASH
FLASH (ESPA�OL)ADOBE
AGGREGATORS
USER GROUPS |
|



