3

I am implementing Cut Copy Paste in my application like cacoo. but I face problem during these operation. i'm using idea behind cut copy paste

var className:String = getQualifiedClassName(objcut.getItemAt(i))
var klass:Class = getDefinitionByName(className) as Class
var cloneObject:* = new klass()

so i'm not able to preserve all property of object. There is any other idea to perform these operation in flex 4.how can i copy an Graphical object in Flex 4(as3). Copy an Object and paste multiple times.

ketan
  • 19,129
  • 42
  • 60
  • 98
Devendra
  • 1,864
  • 6
  • 29
  • 49

1 Answers1

0

The simplest way to make a copy of object with properties is using ByteArray:

public static function copy(value:Object):Object
{
    if (!value)
        return null;

    //register object class to prevent Error #1034: Type Coercion failed
    registerClassAlias(getQualifiedClassName(value), value.constructor);

    var buffer:ByteArray = new ByteArray();
    buffer.writeObject(value);
    buffer.position = 0;
    var result:Object = buffer.readObject();
    return result;
}

But you can still get the error #1034 for nested classes. You need register aliases for all nested classes to prevent this before making copy, for example in some startup method.

fsbmain
  • 5,267
  • 2
  • 16
  • 23
  • thanks,but this is not working for custom group componnent...how i register a custom component?? – Devendra Jan 14 '13 at 07:01
  • You can register any class by calling registerClassAlias(getQualifiedClassName(value), value.constructor); where value is your custom component although this utility copy method usually is used to copy simple objects like TextFormat, make a copy of complex visual object can even throw exceptions sometimes. – fsbmain Jan 14 '13 at 08:31
  • i've all visual components,i'm developing a tool like www.cacoo.com a dragramming tool. but cut copy paste of an display object crate problem, – Devendra Jan 14 '13 at 10:03
  • mxml does not have a constructor so how i achieve this? @fsbmain – Devendra Jan 19 '13 at 10:12