Expand my Community achievements bar.

Sharing Custom Objects

Avatar

Level 2

Hello Guys,


I'm sending custom objects using the "value" property of the ShareProperty class. However when i try to get this object after it has being sent through the network, it seems it was converted in a Array(HashMap). So, how can i send and receive custom objects using the ShareProperty class?

Thanks

Eduardo Dias

3 Replies

Avatar

Former Community Member

Hi,

When you send a complex object, it is converted into a ByteArray and when you get it back, it is reconverted back. What is the complex object that you are sending ? If its a class , have you called MessageItem.registerBodyClass(ClassName); for the class?.

If you are sending a complexObject, you need to register that Class and all the Classes contained inside that.  If you could let us know, what is the composition of your class you are sending and what are you registering , then we can help you.

For reference, you are look at ComplexObjectTransfer example.

SharedProperty just contains a collectionNode like any model and calling a .value API publishes that object. If its not a simple Object, you may need to do all these registering before you use SharedProperty to publish you object.

Thanks

Hironmay Basu

Avatar

Level 2

Hello,

I'm using the MessageItem.registerBodyClass to keep the instance of my class. However, it doesn't work when one of the class constructor parameter is required. For example, look at this class below, if i remove the id parameter, the instance is preserved and i'm able to cast the object, but if it has any required parameter, the object is converted in ByteArray class.

----------------------------------------------------------------------------------------------------------------------
| Class Test

----------------------------------------------------------------------------------------------------------------------

package
{
    public class Test
    {
        public function Test(id:int)
        {
        }

    }
}

Any idea?

Avatar

Former Community Member

Hi Eduardo,

Unfortunately, what you're seeing is a limitation in the Flash Player, which affects anyone doing de/serialization of typed objects which have constructor params. For example,

http://troyworks.com/blog/2007/09/12/as3-serialization-and-deserialization-bytearray-bitmapdata-regi... shows how BitmapData is affected by this.

Luckily, if it's a class of your own creation, you can avoid this problem by just having public getter/setters for each required property, and nothing in the constructor.

nigel