From: Patrick M. <pat...@gm...> - 2007-07-09 03:39:59
|
Hey old mate, Your code looks good to me, the _explicitType, the RemoteClass, all that is fine. I'm thinking it probably has to do with this piece here: _testObjAC = new ArrayCollection( ArrayUtil.toArray(evt.result) ); Have you tried simply tracing evt.result is TestObj? The thing that might help you is looking at it in Charles. Normally it should be able to tell you if php has sent back a typed object or a dummy object. If it sends back a typed object, then the error is on the Flash side, somewhere along the line Flash is not using the RemoteClass info for some bizarre reason. Let me know. Patrick 2007/7/8, Stephen Downs <st...@pl...>: > I'm having a very difficult time understanding why my custom class objects > returned from amfphp are being cast as generic Object instances instead of > instances of their class. > > I am using Flex Builder 2, AMFPHP 1.9, and using RemoteObject, which follows > Alessandro's terrific example ( > http://www.sephiroth.it/tutorials/flashPHP/flex_remoteobject/ > ). > > I set up a project exactly as in Alessandro's example, and the resulting > ArrayCollection is properly populated with Person class instances. All well > and good. > > > Now I try to create an example from scratch, but it doesn't work. Here's how > I set it up (apologies in advance for sending all this code, but I've > literally wasted a day and a half trying to fix this): > > On my server, I have amfphp installed in the amfphp2 directory. My services > and php classes are set up as follows: > > amfphp2/services/com/mycompany/timesheet/TestObjService.php > (my service) > amfphp2/services/com/mycompany/timesheet/TestObj.php (my > custom class) > > -------------------------------------------------------------------- > TestObjService.php: > > > <?php > > require_once "./TestObj.php"; > > class TestObjService { > > function getTestObj() { > $tObj = new TestObj(); > $tObj->testProp = "Test prop set"; > return $tObj; > } > } > > > -------------------------------------------------------------------- > TestObj.php: > > > <?php > > class TestObj { > var $testProp; > > // explicit actionscript package > var $_explicitType = "com.mycompany.timesheet.TestObj"; > } > > ?> > > -------------------------------------------------------------------- > -------------------------------------------------------------------- > My Flex Builder project is set up as: > > Test3/Test3.mxml (Application mxml) > Test3/services-config.xml > Test3/com/mycompany/timesheet/TestObj.as (AS custom class) > > -------------------------------------------------------------------- > Test3.mxml: > > > <?xml version="1.0" encoding="utf-8"?> > <mx:Application xmlns:mx="http://www.adobe.com/2006/mxml" layout="absolute" > creationComplete="initApp()"> > > <mx:RemoteObject id="myService" > source="com.mycompany.timesheet.TestObjService" > destination="amfphp" showBusyCursor="true" > > <mx:method name="getTestObj" > result="getTestObjHandler(event)" /> > </mx:RemoteObject> > > > <mx:Script> > <![CDATA[ > > > import com.mycompany.timesheet.TestObj; > import mx.collections.*; > import mx.rpc.events.ResultEvent; > import mx.utils.ArrayUtil; > > > [Bindable] > private var _testObjAC:ArrayCollection; > > > public function initApp():void { > myService.getTestObj(); > } > > > private function getTestObjHandler(evt:ResultEvent):void > { > _testObjAC = new ArrayCollection( ArrayUtil.toArray(evt.result) ); > // Returns Object instead of TestObj instance! > trace(_testObjAC.getItemAt(0)); > } > > > ]]> > </mx:Script> > > > </mx:Application> > > -------------------------------------------------------------------- > TestObj.as class: > > > package com.mycompany.timesheet { > > > [RemoteClass(alias="com.mycompany.timesheet.TestObj")] > [Bindable] > public class TestObj { > public var testProp:String; > } > > > } > > > -------------------------------------------------------------------- > services-config.xml (this same file works using Alessandro's example): > > > <?xml version="1.0" encoding="UTF-8"?> > <services-config> > <services> > <service id="amfphp-flashremoting-service" > class="flex.messaging.services.RemotingService" > messageTypes="flex.messaging.messages.RemotingMessage"> > <destination id="amfphp"> > <channels> > <channel ref="my-amfphp"/> > </channels> > <properties> > <source>*</source> > </properties> > </destination> > </service> > </services> > <channels> > <channel-definition id="my-amfphp" > class="mx.messaging.channels.AMFChannel"> > <endpoint uri="http://localhost/amfphp2/gateway.php" > class="flex.messaging.endpoints.AMFEndpoint"/> > </channel-definition> > </channels> > </services-config> > > > -------------------------------------------------------------------- > -------------------------------------------------------------------- > Additional notes: > > The compiler arguments for Test3.mxml are set to: > -locale en_US -services "services-config.xml" > > > For now I'll have to parse through the resulting array and cast each item to > my custom class in AS. Not an ideal option. > > Thanks for any input. > Steve > > > ------------------------------------------------------------------------- > This SF.net email is sponsored by DB2 Express > Download DB2 Express C - the FREE version of DB2 express and take > control of your XML. No limits. Just data. Click to get it now. > http://sourceforge.net/powerbar/db2/ > _______________________________________________ > amfphp-general mailing list > amf...@li... > https://lists.sourceforge.net/lists/listinfo/amfphp-general > > |