2 Replies Latest reply on Aug 28, 2009 10:43 AM by Barna Biro

    Cloning an Object

    Rashonski

      I've been trying to clone one of my custom objects for a few days now and tried all examples i could find. I also added "[RemoteClass]" before every class.

      I used a custom (which is probably the same) and the mx.utils.objectutils.copy function:

       

      public static function clone(value:Object):Object
      {
          var buffer:ByteArray = new ByteArray();
          buffer.writeObject(value);
          buffer.position = 0;
          var result:Object = buffer.readObject();
          return result;
      }

       

      Both gave me the same error message:

       

      "ArgumentError: Error #1063: Argument count mismatch on basecreatures.water::Naga(). Expected 1, got 0.
          at flash.utils::ByteArray/readObject() [....]"

       

      The class Naga is being extended by the class Creature, which both require some arguments. I used it like this:

       

      Game.player[ownerid].creaturelist.push(Game.clone(target));

       

      target is an object of the class Naga which is working perfectly. Using some other clone methods, the cloned object didn't get the functions of the Creature class.