I'll need to clone some objects that have several types of instances. I've searched using a search engine and found some examples however I got error after I tested them.
Example: AS3 - Clone an object
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);
This gives me error: Line.as, Line 12, Column 3 1170: Function does not return a value.
Example: 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);
This code is giving me warning: TypeError: Error #1064: Cannot call method global/com.gamua.flox.utils::cloneObject() as constructor. at 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);
This gives me error: org\as3commons\lang\ObjectUtils.as, Line 211, Column 69 1046: Type was not found or was not a compile-time constant: IIterator.
Which one is the best for cloning an object and how can I fix the errors? Or is there a good library?