Trouble cloning an extended ByteArray?

I think this is because tmp is of type ByteArray, not of type MyByteArray. If you make tmp of type MyByteArray, it should return an object of the same type, using writeObject I think? Or you may need to typecast it.

No, tmp needs to be of type ByteArray. This is the typical way of cloning objects in AS3, implemented also as ObjectUtil.copy(). Typecasting doesn't help as tmp.writeObject() doesn't save any fields of MyByteArray (in this minimal example MyByteArray has no fields, but it has in my application).

The weird thing is that if MyByteArray does not extend ByteArray, then everything works OK, i.e. , b2 is of type MyByteArray after cloning. – bartekb May 18 '09 at 12:18.

ByteArray is likely handled as a special case for object serialisation, so I doubt you'll get around it. Attempting to subclass ByteArray sounds like a code smell to me. I'd look at using encapsulation rather than inheritance to solve your problem.

Thanks for input. I intentionally used inheritance and not encapsulation as I was trying to trick Flash Player a bit... I was trying to pass MyByteArray instead of ByteArray as an argument to FileReference#save(), hoping that I could "stream" data to a local file rather than write the whole file at once (MyByteArray would be producing data in real-time). I've described this problem here: stackoverflow.Com/questions/869816/… – bartekb May 19 '09 at 13:11 Try implementing IDataInput on your object.

Failing that, the only solution I know of is AIR-only (FileStream) – Richard Szalay May 19 '09 at 13:34 After reading up about it, it looks like you will need to stream your content into a ByteArray (which implements IDataOutput) and then save that instance of ByteArray. When reloading, you can read from it (it also implements IDataInput). – Richard Szalay May 19 '09 at 13:37 My content is larger than the available memory, so I can't stream the whole content to the in-memory ByteArray.

I need to stream it directly (or in chunks) to a file, much as in the FileStream class (AIR-only). However, it seems to me that it's not possible in Flash 10... – bartekb May 19 '09 at 22:04.

I cant really gove you an answer,but what I can give you is a way to a solution, that is you have to find the anglde that you relate to or peaks your interest. A good paper is one that people get drawn into because it reaches them ln some way.As for me WW11 to me, I think of the holocaust and the effect it had on the survivors, their families and those who stood by and did nothing until it was too late.

Related Questions