I have flex mxml custom component(Graphic).According to requirement a need to copy them as copy or cut operation.but problem in the registerClassAlias() method,how it will work for custom graphic or Group(or UIComponents) components.
var className:String = getQualifiedClassName(zorder.getItemAt(0));
_saveIn.clear();
registerClassAlias(className, zorder.getItemAt(0) as Class);
_saveIn = SharedObject.getLocal("save");
_saveIn.data.value1 = new ByteArray();
_saveIn.data.value1.writeObject(zorder.getItemAt(0));
_saveIn.data.value1.position = 0;
_saveIn.flush();
It's not possible to make a full copy of any display object via ByteArray with
registerClassAlias->writeObject->readObject
approach. It works only with simple objects, for example data objects (like TextFormat, value objects and so). In any case you have to test the copy method for each type of your object to be sure it works properly.Example of coping
Shape
, the simplest display object:Output:
So, you can try to register the
flash.geom.Transform
before coping:but this lead to another error:
Actually,
DisplayObject
coping is the old topic and you can google for lots of posts about this by errors I mentioned above (especially the last one), but the answer is: You can't copy display objects in via ByteArray, you need to write custom methods for creating a copy of given TextField, Sprite or VBox and copy all the properties manually.Ok, this blog post has a simple solution... you use
getDefinitionByName()
:So something like this in your code: