Arrays AS3-为什么类数组不能正常工作?

Arrays AS3-为什么类数组不能正常工作?,arrays,actionscript-3,class,object,Arrays,Actionscript 3,Class,Object,我有一门课叫tOne。课程代码如下 public class tOne extends MovieClip { private var _root:MovieClip; public var tPath:Array = new Array(); public var index:int = 0; public function tOne() { this.addEventListener(Event.ADDED, beginCla

我有一门课叫tOne。课程代码如下

public class tOne extends MovieClip {
    private var _root:MovieClip;
    public var tPath:Array = new Array();

    public var index:int = 0;       

    public function tOne() {
        this.addEventListener(Event.ADDED, beginClass);
        this.addEventListener(Event.ENTER_FRAME, gameLoop);
    }

    private function beginClass(e:Event):void {
        _root = MovieClip(root);            
        tPath = _root.tMovingPath; //Sets the tPath array to a bunch of coordinates
    }

    private function gameLoop(e:Event):void {
        if (tPath[index] != null) {             
            this.x = tPath[index].xCoord;
            this.y = tPath[index].yCoord;
            tPath.splice(index, 1); //Here is the problem

            index++;
        }
    }
}
我正在创建这个类的三个实例,所以我有三个音调对象。现在我的问题是,当我使用“tPath.splice(index,1)”时,它不会从一个音调对象中删除该索引,而是从所有三个对象中删除该索引

因此,如果在第一个音调对象中,我的数组长度为3,并移除其中一个,那么它会移除另外两个音调对象中的一个

我不明白为什么

谁能给我解释一下发生了什么事吗?

在你的台词中

tPath = _root.tMovingPath;
您正在将tPath设置为引用阵列。所有三个对象的引用都将指向同一数组

您需要做的是对该数组进行一次排序。一种方法是:

tPath = _root.tMovingPath.concat();

这非常有效。我一直认为,如果将一个数组设置为另一个数组,则会复制内容。我错了。无论如何,谢谢你。