0

I'm writing a clone function for a class of mine.

        var buffer:ByteArray = new ByteArray();
        buffer.writeObject(this);
        buffer.position = 0;
        var gameblock:* = buffer.readObject();

Now at the last line when the time comes to read the object. I get these three errors together:

TypeError: Error #1009: Cannot access a property or method of a null object reference. TypeError: Error #1034: Type Coercion failed: cannot convert Object@c60efe9 to model.BlockData. TypeError: Error #1034: Type Coercion failed: cannot convert Object@c5141c1 to flash.geom.Matrix.

The class 'this' contains a user defined class BlockData and a Point . The errors are coming on that. How do you think I should clone this class?

I do overwrite the BlockData and the point again to make sure they get returned properly

Fahim Akhter
  • 1,617
  • 5
  • 31
  • 49
  • 1
    "better" is for your class to implement [IExternalizable](http://help.adobe.com/en_US/FlashPlatform/reference/actionscript/3/flash/utils/IExternalizable.html) to improve ByteArray serialisation and as fsbmain said, displayobjects can't be copied – Lukasz 'Severiaan' Grela Feb 27 '13 at 22:01

1 Answers1

1

Check this answer for better copy method with using of registerClassAlias method, but remember, that you can use this method only for simple cases, for example copy of data objects like TextFormat or Value Objects, you can't copy DisplayObject and its successor.

Community
  • 1
  • 1
fsbmain
  • 5,267
  • 2
  • 16
  • 23