Question

I want to clone a class object. I tried following from here:

package
{
    import flash.net.registerClassAlias;
    import flash.utils.ByteArray;

    public class MyClass
    {
        public var property1:String;
        public var property2:Array;

        public function clone():MyClass
        {
            registerClassAlias("MyClass", MyClass);

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

            return bytes.readObject() as MyClass;
        }
    }
}

BUT this only works when the class has a default constructor and not when it has parameterized constructor:

Any idea on how to clone a class object when the class has a parameterized constructor?

Regards

No correct solution

Licensed under: CC-BY-SA with attribution
Not affiliated with StackOverflow
scroll top