cut copy paste with DisplayObject(Group ,UIComponent) in action script 3 flex 4

偶尔善良 提交于 2019-12-12 15:21:30

问题


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.


回答1:


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.



来源:https://stackoverflow.com/questions/14273989/cut-copy-paste-with-displayobjectgroup-uicomponent-in-action-script-3-flex-4

易学教程内所有资源均来自网络或用户发布的内容,如有违反法律规定的内容欢迎反馈
该文章没有解决你所遇到的问题?点击提问,说说你的问题,让更多的人一起探讨吧!