[osflash] openAMF ValueObject problem

Bas van Gils bas at asknow.nl
Fri Nov 18 11:06:25 EST 2005


Hi,

I have a problem getting a ValueObject to the client from a service
using openAMF.

The situation:
When the responder.onResult(re: ResultEvent) function is executed after
a service call, I want to cast the value of re.result to a ValueObject.
This is done by:
--------------------------------
var vo : ValueObject = ValueObject(re.result);
--------------------------------

Now, when I try to trace the vo variable, "null" is traced, whichs means
that the cast has failed (according to the Flash docs). But when I trace
all properties of the re.result with:
--------------------------------
for (var p in re.result)
{
	trace("re.result["+p+"] == "+re.result[p]);
}
--------------------------------

... I see that the id-property is correctly filled with a value of 12
(see the id property in the java-class below), so it looks like openAMF
has correctly serialized the java-ValueObject to AMF, but the Flash
Player cannot cast the re.result to a ValueObject. 

Does anyone have an explanation why this is happening?
I'm ColdFusion Standard. Is that that problem? Should I be using the
J2EE version?

Ofcourse I added the mapping in "openamf-config.xml"

	<custom-class-mapping>
		<java-class>test.server.vo.ValueObject</java-class>
		<custom-class>test.client.vo.ValueObject</custom-class>
	</custom-class-mapping>



my ActionScript-class:
--------------------------------------------------------
class test.client.vo.ValueObject
{
	private static var registered : Boolean =
Object.registerClass("test.server.vo.ValueObject", ValueObject);

	private var id : Number = 12; // NOTE: 12 is just for testing!
	
	public function ValueObject()
	{
		trace("ValueObject.constructor()");
	}	
	
	public function getId() : Number
	{
		return this.id;
	}
	
	public function setId(id: Number) : Void
	{
		this.id = id;
	}
}
---------------------------------------------------------

my Java-class:
---------------------------------------------------------
package test.server.vo.ValueObject;

import java.io.Serializable;

public class ValueObject implements Serializable
{
	public Integer id;
	
	public ValueObject()
	{
	}
	
	public Integer getId()
	{
		return this.id;
	}
	
	public void setId(Integer id)
	{
		this.id = id;
	}
}
---------------------------------------------------------


Thanks!

Bas.


PS.
I found a workaround by passing the re.result variable to the
constructor of the AS ValueObject and then copying the properties of the
re.result to the class-properties of the ValueObject, but I do not
prefer this "solution".



More information about the osflash mailing list