我需要克隆一些具有多种类型实例的对象。我使用搜索引擎搜索并找到了一些示例,但是在测试它们后出现错误。
示例:AS3 - 克隆对象
import Line;
import OtherClass;
// Set lines
var obj1:Object={
environmentLine:new EnvironmentLine(),
lineX:100,
lineY:100
};
addChild(obj1.environmentLine);
var line:Line = new Line();
line.clone(obj1);
这给了我错误: Line.as,第 12 行,第 3 列 1170:函数不返回值。
示例:https ://gist.github.com/PrimaryFeather/6914861
import com.gamua.flox.*;
import com.gamua.flox.utils.*;
import com.gamua.flox.events.*;
// Set lines
var obj1:Object={
environmentLine:new EnvironmentLine(),
lineX:100,
lineY:100
};
addChild(obj1.environmentLine);
var clone:Object = new cloneObject(obj1);
这段代码给了我警告:TypeError: Error #1064: Cannot call method global/com.gamua.flox.utils::cloneObject() as constructor。在 Untitled_07_fla::MainTimeline/frame1()
import org.as3commons.lang.ObjectUtils;
var num:int = 0;
// Set lines
var obj1:Object={
environmentLine:new EnvironmentLine(),
lineX:100,
lineY:100
};
var objectUtils:ObjectUtils = new ObjectUtils();
objectUtils.clone(obj1);
这给了我错误:org\as3commons\lang\ObjectUtils.as, Line 211, Column 69 1046: Type was not found or is not a compile-time constant: IIterator.
哪一个最适合克隆对象,如何修复错误?或者有没有好的图书馆?