function setLabel():void {
var cloneObject = UtilFunctions.clone(t_1) as VBox;
ticketList.push(cloneObject);
tickets.addChild(cloneObject);
}
我正在获取 t_1 id(id 是 VBox 的属性),我想他包含的所有内容(所有子容器)也将被复制,然后将其保存到数组中,最后将其添加到某个可视容器中,因此制作一些视觉对象的副本,但这不起作用,所以我想知道这是否可能,我认为的另一个解决方案是将它放入模块然后动态创建模块并将它们添加到 displayList,你能给我一些提示?还有哪个更快?
**UPDATE**
package library
{
import flash.utils.describeType;
import flash.utils.getDefinitionByName;
import flash.utils.getQualifiedClassName;
public class UtilFunctions
{
public static function newSibling(sourceObj:Object):* {
if(sourceObj) {
var objSibling:*;
try {
var classOfSourceObj:Class = getDefinitionByName(getQualifiedClassName(sourceObj)) as Class;
objSibling = new classOfSourceObj();
}
catch(e:Object) {}
return objSibling;
}
return null;
}
public static function clone(source:Object):Object {
var clone:Object;
if(source) {
clone = newSibling(source);
if(clone) {
copyData(source, clone);
}
}
return clone;
}
public static function copyData(source:Object, destination:Object):void {
//copies data from commonly named properties and getter/setter pairs
if((source) && (destination)) {
try {
var sourceInfo:XML = describeType(source);
var prop:XML;
for each(prop in sourceInfo.variable) {
if(destination.hasOwnProperty(prop.@name)) {
destination[prop.@name] = source[prop.@name];
}
}
for each(prop in sourceInfo.accessor) {
if(prop.@access == "readwrite") {
if(destination.hasOwnProperty(prop.@name)) {
destination[prop.@name] = source[prop.@name];
}
}
}
}
catch (err:Object) {
;
}
}
}
}
}