views:

27

answers:

1

OK, I am passing a complex object from my .NET library to my Flex application via WebOrb. In order to automatically translate, I am using the [RemoteClass] meta data tag as follows:

[RemoteClass(alias="test.PlanVO")]
public class Plan
{
    [SyncId]
    public var id:int;

    public var Name:String;
}

This works absolutely fine, until I try to extend the Plan class to contain an array of complex items:

.NET:

public class PlanVO
{
    public int id  { get; set; }
    public string Name { get; set; }
    public List<PlanElementVO> children { get; set; }
}

public class PlanElementVO
{
    public string elementName { get; set; }
}

ActionScript:

[RemoteClass(alias="test.PlanVO")]
public class Plan
{
    [SyncId]
    public var id:int;

    public var Name:String;

    public var children:ArrayCollection;
}

[RemoteClass(alias="test.PlanElementVO")]
public class PlanElement
{
    public var elementName:String;
}

In this case, even when children are returned by the .NET library, the children property of the ActionScript Plan class is null.

I have tried changing the children field to a property like this:

private var _children:ArrayCollection;
public function get children():ArrayCollection 
{
    return _children;
}
public function set children(o:*):void
{
    if(o is ArrayCollection)
        _children = o;
    else if(o is Array)
        _children = new ArrayCollection(o);
    else
        _children = null;
}

but the set function never gets called.

What can I do to get the children into my Flex app in this way?

Thanks!

A: 

It's no surprise to me that the set method s never called. The object should, theoretically, return from the server with the items already set.

That said, I did not think that an ArrayCollection would match to a server side object. Try using an Array in Flex. In .NEt you should use one of the "supported" types. If List is an implementation of IList, then you're probably fine.

Here is the .NET to Flash Player WebORB Conversion Chart

www.Flextras.com
An Array! Of course! DUUUUUH!!!Thanks very much, simply changing it from the ArrayCollection worked perfectly!
Glad to help! If you need an ArrayCollection, you can always add a method like getChildrenAsArrayCollection that does the conversion for you. Be careful about adding new properties to the Flex class, though, as it may disturb the automatic AMF conversion.
www.Flextras.com