RemoteObjectAMFO update to latest Cairngorm
July 26th, 2006 英文
为了表现最新的Cairngorm包那些RemoteObjectAMF0的类别和标本代码已经更新了。在labs.adobe.com的网站你可以找到Flex2的Cairngorm。从现在开始我RemoteObjectAMF0的类别不会包括Cairngorm。
现在的RemoteObjectAMF0包,包括两个例子。第一就是更新的Cairngorm注册例子 (例子/代码程序)。
我所创造的新例子是一个non-Cairngorm AMFPHP的例子。(例子/代码程序)。
Entry Filed under: Adobe Flex, Flex,AMF,PHP, Rich Internet Applications



42 Comments Add your own
1. Matt Brailsford | July 30th, 2006 at 3:51 am
Hi,
I’d just like to say that your work is fantastic.
I do have one question, if i use it as documented, it does work great, but i am trying to get it to work using Darron Schall’s method which can be found here:
http://www.darronschall.com/weblog/archives/000234.cfm
I think the problem lies within the RemoteObjectAMF0 class in the setQueryResult and Faul methods, the dispatched event is not being picked up.
Would you know of any way to get this to work?
ps, in the setProperty method, i think you have mis spelled “destination” and in the setQueryFault method i didn’t know if you wanted to use the FaultEvent.FAULT constant, rather than the sting “fault”
2. sectore | July 30th, 2006 at 6:33 am
Hi Renaun,
thanks for sharing your code.
At the example above I had a problem to execute the LoginCommand. It took me some minutes to realize that the CairngormEventDispatcher had not been initialized before. The function named “loginUser” at Login.mxml dispatched the LoginEvent without an instance of the CairngormEventDispatcher. When I changed the code to
CairngormEventDispatcher.getInstance().dispatchEvent( event );it has worked well.Anyway, great work Renaun!
Best
sectore
–
http://www.websector.de/
3. Renaun Erickson | July 31st, 2006 at 7:41 am
matt,
I made the string changes you recommended. As far as the Fault event not being called I would have to see your code, it works here. I updated the Example and source with the small changes and a Fault example.
You can send me some example code if you want me to look at it further.
sectore,
I am not sure why you had to do this as the code works straight from the source for me. Did you modified the source any? what version are you using of Cairngorm? are you using the Cairngorm source or SWC?
Renaun
4. Mike Britton | July 31st, 2006 at 8:40 am
Thanks for putting this together.
I typically establish my AMFPHP gateway as ‘http://www.someurl.com/flashservices’.
From the AMFPHP gateway, is ‘amfphp1_2/services/com/multispan/samples/CairngormAMFPHPLoginExample/Login.php’ the same as ‘http://www.someurl.com/flashservices/services/com/multispan/samples/CairngormAMFPHPLoginExample/Login.php’?
That is, should I place the package in my AMFPHP /services directory?
5. Renaun Erickson | July 31st, 2006 at 8:57 am
The amfphp1_2 is where the gateway.php is and the services folder is the default location for AMFPHP for the AMFPHP service classes.
Place the PHP files starting from com/renaun/etc… (get the newer code) in your services folder under the AMFPHP installation root.
6. Matt Brailsford | July 31st, 2006 at 10:57 am
Hi,
I’ve uploaded my code so far, which is basically just the login sample, so you should be pretty familiar with it.
I am using fluorine, which does support AMF3 but has to be used the same way as Remoting at the mo, so i have commented out the AMF0 encoding bit, which as i mentioned before works fine the way you documented it, but if i switch it round to Darron Schall’s method, i never get a measage from the methods mentioned before.
Anyway, you can access my code from here:
http://www.gradiation.co.uk/FlexDemo.zip
Your help is greatly apprechiated.
7. Mike Britton | July 31st, 2006 at 12:32 pm
Thanks sectore for finding that problem w/ CainrgormEventDispatcher — that fixed my problem and I now have a semi-working version of this.
Matt, as soon as I take a nap and have a beer I’m going to take a look at your code. It would be nice to have AMF3 working since (I think) that means we could use the standard RemoteObject component.
8. Renaun Erickson | July 31st, 2006 at 1:31 pm
I have not come across the CairngormEventDispatcher issue, what versions of Cairngorm are you using? Are you using the latest from labs.adobe.com? is it source or SWC?
Matt, I am going to look at your code here soon.
I did start looking into AMF3 which would make the RemoteObjectAMF0 less important unless you did not want to upgrade your old AMF classes. Flourine or SabreAMF say they support AMF3 but that leaves all the channel and destination implementation glue left to figure out that Flex now uses in the “services-config.xml” config file. I haven’t had time to check it out in depth.
Renaun
9. Matt Brailsford | July 31st, 2006 at 2:50 pm
I know zoli is trying to get something working by the end of the summer for Fluorine, so i was just trying to get something working in the mean time.
If you are trying to figure out the AMF3 glue bits, it might be worth a look at WebORB as it sounds like they are doing something interesting utilizing some of the FDS classes or something, without actually using FDS.
10. Renaun Erickson | July 31st, 2006 at 4:08 pm
Well the CairngormEventDispatcher issue was valid, I guess I have to many versions and in the switch over to using the SWC it appeared. It is fixed now in the sample code thanks sectore.
Matt, Mike,
I also updated the ResponderAMF0.as class to handle IResponder tied to the AsyncToken. This fixes the classes to work as the normal Responder should, and how Darron Schall explains it.
You’ll find the updated source in the same place.
Renaun
PS: I want to go back and clean up the code and document it better once I get a change.
11. Mike Britton | August 1st, 2006 at 10:10 am
I know this is trivial, but BookVO doesn’t run in PHP 4.4.2. I var’ed the properties and it worked:
class BookVO {
var $_explicitType = “BookVO”;
var $name;
var $bookid;
var $publishdate;
function BookVO() {}
}
12. Renaun Erickson | August 1st, 2006 at 10:40 am
Yeah, the zipped source version is for PHP 5 and to get it to work in PHP 4 you need to change the public to var in the BookVO.php.
13. Mike Britton | August 1st, 2006 at 6:38 pm
Once the DataGrid is populated, I see its change event hits viewDetails() to fetch the value from the BookVO. It was blowing up for me, so I switched the function from
lblBook.text = BookVO( dgBooks.selectedItem ).name;
to
var myCollection:ArrayCollection = new ArrayCollection();
myCollection = model.books;
var myCursor:IViewCursor = myCollection.createCursor();
var myValue:String = myCollection.getItemAt(dgBooks.selectedIndex).name;
lblBook.text = myValue;
Is this the “right” way to do it?
14. Mike Britton | August 1st, 2006 at 6:40 pm
Sorry - change that to:
var myCollection:ArrayCollection = new ArrayCollection();
myCollection = model.books;
var myValue:String = myCollection.getItemAt(dgBooks.selectedIndex).name;
lblBook.text = myValue;
The cursor was unnecessary.
15. Renaun Erickson | August 1st, 2006 at 8:01 pm
Mike,
I am interested to know why it was blowing up. They change you did works fine as its just accessing the Collection directly instead of through the Datagrid.
16. Mike Britton | August 1st, 2006 at 9:18 pm
TypeError: Error #1034: Type Coercion failed: cannot convert Object@d8fb0e1 to com.renaun.samples.login.vo.BookVO.
17. Renaun Erickson | August 1st, 2006 at 9:21 pm
Its probably because you did not specify the type of objects in the ArrayCollection. In your ModelLocator do you have something like this:
[ArrayElementType("com.renaun.samples.vo.BookVO")]
public var books:ArrayCollection;
18. Mike Britton | August 1st, 2006 at 9:40 pm
Yep, it still threw that error. Which brings me to ask: is it bad form to access the model directly from a view like I did? It feels bad.
19. sectore | August 2nd, 2006 at 2:11 pm
Mike,
cast the resultEvent at the resultHandler (LoginCommand) with a helper method as following:
// change in the method "onResult"
ModelLocator.getInstance().books = initBookVOs(event.result);
// and add a helper method
private function initBookVOs (resultArray: Array): ArrayCollection
{
[ArrayElementType("com.renaun.samples.vo.BookVO")]
var tempArray: ArrayCollection = new ArrayCollection();
for (var book: String in resultArray)
{
tempArray.addItem(new BookVO(resultArray[book]));
}
return tempArray;
}
In the same way you have to change the BookVO:
package com.renaun.samples.login.vo
{
import com.adobe.cairngorm.vo.ValueObject;
import flash.net.registerClassAlias;
[RemoteClass(alias="com.renaun.samples.login.vo.BookVO")]
[Bindable]
public class BookVO implements ValueObject
{
public var name : String;
public var bookid : String;
public var publishdate : String;
public function BookVO(source:Object=null)
{
if (source != null)
{
for (var element:String in source)
{
try
{
this[element] = source[element];
}
catch (error:Error)
{
// throw new Error (”BookVO” + error);
}
}
}
}
}
}
P.S. Renaum, I’m using the latest Cairngorm Framework from labs.adobe.com.
Best
sectore
–
http://www.websector.de/
20. Renaun Erickson | August 2nd, 2006 at 2:15 pm
I forgot to mention that Mike’s issue with the BookVO coercion error was a incorrect linve of code in BookVO.php.
Needed line:
var $_explicitType = “com.renaun.samples.login.vo.BookVO”;
21. Mike Britton | August 3rd, 2006 at 11:06 am
Thanks sectore! Renaun set me straight as well.
22. sectore | August 3rd, 2006 at 1:48 pm
Renaun,
if I use your code with the Cairngorm Framework (*.as classes, not the *.swc) and run the “CairngormAMFPHPExample2.mxml”, the Flash Player throws at executing the viewDetails() method the following error message:
TypeError: Error #1034:
Type Coercion failed:
cannot convert Object@79ab641 to com.renaun.samples.login.vo.BookVO.
at CairngormAMFPHPExample2/::viewDetails()
at CairngormAMFPHPExample2/__dgBooks_change()
at flash.events::EventDispatcher/flash.events:EventDispatcher::dispatchEventFunction()
at flash.events::EventDispatcher/dispatchEvent()
at mx.controls.listClasses::ListBase/mx.controls.listClasses:ListBase::mouseUpHandler()
at mx.controls::DataGrid/mx.controls:DataGrid::mouseUpHandler()
Casting the bookVO in the method named onResult (LoginCommand.as) as described above solves this problem.
I think the array of the result has got elements typed as “simple” Object (not BookVOs). But I’m not sure because haven’t got the Flex Debugger on my Powerbook…
P.S. I’m using Flex SDK, FP 9.0.16.0, AMFPHP 1.2, PHP5.
Best
sectore
–
http://www.websector.de/
23. Mike B | August 11th, 2006 at 2:11 pm
Nothe the Cairngorm and Remote object examples are not showing the date in the published date column of the grid.
I get the following trace warnings in the FB debugger.
TypeError: Error #1034: Type Coercion failed: cannot convert “August 31, 2006, 12:00 am” to Date.
TypeError: Error #1034: Type Coercion failed: cannot convert “September 1, 2006, 12:00 am” to Date.
TypeError: Error #1034: Type Coercion failed: cannot convert “November 1, 2006, 12:00 am” to Date.
any ideas?
thanks for your effort!
24. Renaun Erickson | August 14th, 2006 at 4:54 pm
showBusyCursor has been implemented and is in the the source now.
25. Evert Pot | August 15th, 2006 at 6:45 am
Hi Renaun,
Thanks for the heads up, SabreAMF now does support the Flex messaging system glue..
Evert
26. Stefan Schmalhaus | August 21st, 2006 at 5:39 am
Is there any solution to the date mapping problem between Flex and PHP? (Comment #23)
27. Renaun Erickson | August 21st, 2006 at 7:29 am
AMFPHP as of yet only lets you define a “Date” type for returned values of a remote method. There is no distinct way to know a field in PHP is a date, so you will have to explicit do the conversion manually.
This is more of a short coming of PHP then AMF.
28. Sam Shrefler » Flex&hellip | September 12th, 2006 at 11:27 am
[...] After further investigation, I was still a little confused as how to accomplish this using a non-beta, standard (free) version of WebOrb.NET. Well, it turns out; version WebOrb v2.0 works great with AMF0, the remoting format from Flash 8. This led me to Renaun’s RemoteObjectAMF0 which easily plugs into a Cairngorm ServiceLocator. [...]
29. Sam Shrefler | September 18th, 2006 at 8:39 am
Renaun:
Thank you so much for the excellent tag. I’ve been able to use it with WebOrb.NET as well with great results. I was looking to attempt to extend the tag so that it would include a timeout. Reason being, i’d like to throw up a modal window when a request is sent to the server, but if for some reason a response isn’t returned, the user would be locked out. It seems to make most sense to me to incorporate right into the Service call, a timeout that if it occured, it would return a fault event? What are your thoughts on this?
Thanks
Sam
30. Renaun Erickson | September 18th, 2006 at 10:34 am
You could extend the class to provide this functionality.
If you are using Cairngorm you could also do the same thing with a base Command object.
I believe this is something specific to your needs (maybe others too), but to keep the class close to the generic RemoteObject I would consider this feature an add-on. If you need any help let me know it should be fairly easy.
31. Sam Shrefler | September 19th, 2006 at 7:20 am
Renaun:
Could you elaborate on where to do this using a base Command object in Cairngorm. I agree that this would be an add-on in order to keep it similar to RemoteObject..but it seems like this would be something that many people would be looking to have. I’m wondering if it is implemented somewhere else and I’m missing it….
32. Matt Brailsford | October 17th, 2006 at 2:03 am
Hi Renaun,
I’ve been happily using your RemoteObject with Fluorine and Flex 2 for a few weeks now, however i have come up with a problem.
Collections of objects that are returned from fluorine are converted into basic Arrays instead of ArrayCollections (which are needed for binding)
I’m not sure if this is a Fluorine thing, or RemoteObject thing, but whilst looking into it i found that all RPC Services in flex have a makeObjectsBindable property which forces Arrays to ArrayCollections.
I was just wondering, with your knowlege of the internals of RemoteObject, do you know how this is implemented? is it the RemoteObject that forces them? or doe it tell the service to do it? and how could it be implemented into your RemoteObject?
Any help, as always, is greatly apprechiated.
Many thanks
Matt
33. Renaun Erickson | October 17th, 2006 at 9:13 am
Matt find the udpates here…
34. Sam Shrefler » Flex&hellip | October 17th, 2006 at 11:16 am
[...] Using Service Capture , an ABSOLUTELY fantastic tool and Fluorine with AMF3, still seems to be a problem. Also, I wanted to try and use the RemoteObject tag with my solution to make using .NET a little less coupled. Well, it turns out; Fluorine still seems to work great with AMF0, the remoting format from Flash 8. This led me to Renaun’s RemoteObjectAMF0 which easily plugs into a Cairngorm ServiceLocator. So there’s the pieces, now to put together the puzzle. [...]
35. Sam Shrefler » Adob&hellip | October 18th, 2006 at 11:20 am
[...] Using Service Capture , an ABSOLUTELY fantastic tool and Fluorine with AMF3, still seems to be a problem. Also, I wanted to try and use the RemoteObject tag with my solution to make using .NET a little less coupled. Well, it turns out; Fluorine still seems to work great with AMF0, the remoting format from Flash 8. This led me to Renaun’s RemoteObjectAMF0 which easily plugs into a Cairngorm ServiceLocator. So there’s the pieces, now to put together the puzzle. [...]
36. Matt Brailsford | October 27th, 2006 at 4:09 am
Hi Renaun
I’m trying to use RemoteObjectAMF0 in a real simple example, that doesn’t use cairngorm. I’m trying to bind a datagrid to the results public property, however it doesn’t seem to bind.
Don’t suppose you have any ideas why? Or any examples of how best to do it without cairngorm?
Many thanks
Matt
37. Ilya | November 29th, 2006 at 7:31 am
Hi Renaun,
I get the following error, then use RemoteObjectAMF0:
TypeError: Error #1034: Type Coercion failed: cannot convert com.renaun.rpc::RemoteObjectAMF0@4359e61 to mx.rpc.remoting.RemoteObject
I shall be grateful for any help
38. Renaun Erickson | November 29th, 2006 at 8:24 am
It looks like you have some casting wrong somewhere. Is there something in your code where you are doing RemoteObject( roAMF0 )?
Is RemoteObject class present anywhere in your code?
What backend are you using RemoteObjectAMF0 with?
39. Tercüme bürosu | October 30th, 2007 at 9:09 am
Yeah, the zipped source version is for PHP 5 and to get it to work in PHP 4 you need to change the public to var in the BookVO.php…
40. Dan Van Brunt | May 30th, 2008 at 10:14 pm
Renaun,
Can you please provide an example of what you mean regarding your response on 2006-08-21 at 7.29 am regarding AMF, PHP and Date conversions?
I’m currently have this error with Dates as well as passing nested VOs from PHP to Flex using AMFPHP.
eg. TeamVO has a property “players” that I’m trying to pass as an array of PlayerVOs.
Is this even possible?
41. Renaun Erickson » G&hellip | June 16th, 2008 at 9:14 am
[...] example Flex application is from my example code used in the RemoteObjectAMF0 and my SabreAMF example. You can get the my example code [...]
42. Nate Ross | October 1st, 2008 at 1:44 pm
Here is how you map the Date successful using AMFPHP.
Send the date over in milliseconds as a Number. Then you can do the following…
private var _birthdate:Date;
public function set birthdate(value:*):void {
if (value is Number || value is String) {
_birthdate = new Date();
_birthdate.setTime(value);
}
}
public function get birthdate():Date {
return _birthdate;
}
Voila!
Leave a Comment
Some HTML allowed:
<a href="" title=""> <abbr title=""> <acronym title=""> <b> <blockquote cite=""> <cite> <code> <del datetime=""> <em> <i> <q cite=""> <strike> <strong>
Trackback this post | Subscribe to the comments via RSS Feed