views:

600

answers:

3

Hello,

I am trying to serialize & deserialize Vector. using ByteArray Here is my code:

 public static function serializeToString(value:Object):String{

    if(value==null){                
        throw new Error("null isn't a legal serialization candidate");              
    }

    var bytes:ByteArray = new ByteArray();          
    bytes.writeObject(value);           
    bytes.position = 0;         

    return Base64.encodeByteArray( bytes ).toString();           
}

public static function readObjectFromStringBytes(value:String):Object{          

    var result:ByteArray= Base64.decodeToByteArray(value);
    result.position=0;          
    return result.readObject();         
}

No matter what I do, I keep having this error:

RangeError: Error #2006: The supplied index is out of bounds. at flash.utils::ByteArray/readObject()

I am dipertly looking for a solution ..

Thanks in advance Sameer

A: 

Try getting rid of the .position = 0 lines. They aren't necessary and the second one may be what is causing your issue. Also note that toString() is unecessary, as encodeByteArray already returns a String.

Cameron
Error #2006 still there, the strange thing is that the problem only occures when the swf that implements the serialization is loaded into another swf (the loader)But, when I use the serializer swf directly ( without being loaded from a loader swf) the problem dissapear!I call the desrialzer when I press a button, meaning I am 100% sure that the serializer swf is loaded completlyThe string I am deserializing is stored in the loaded swf ..So, I hope this gives you a clue ..
Samir Sabri
I have no idea why it might be failing, sorry. Maybe Base64 is causing the problems? It seems less likely that a heavily-used builtin class (ByteArray) have such an enormous bug in it. Then again, maybe this error only happens in circumstances unique to your app, or is caused by unrelated code elsewhere. I once had an error showing up caused by a bug in a completely unrelated class. It was difficult to find because the buggy class had been working fine (when it should not have been) for days before it started causing errors (and I had not modified the class in question for several days).
Cameron
A: 

I found the problem reason after days of frustration ..

The loader SWF published for player 9, the content SWF published for player 10, I simply republished the loader for player 10, and the Error #2006 disappeared from the loaded SWF

What I wonder about, is that the content uses Vector. type, which is player 10 feature, how come it played correctly inside an older loader ?! Why there is no descriptive regarding different player versions ??

Samir Sabri
A: 

In case you want to send or receive the serialized object graph to server-side code without converting to a string first, see this link.

bob31334
If, further, you would like to serialize/deserialize the object graph in C# on the server side, see this link about how to use FlourineFx to accomplish this.http://www.eggheadcafe.com/software/aspnet/29237818/amf3-serializationdeseri.aspx
bob31334