Remove link between to variables

Greetings!

I’ve banging my head against the wall for a few days now about this problem:

Code:

<?xml version=“1.0” encoding=“utf-8”?>
<mx:Application
xmlns:mx=“http://www.adobe.com/2006/mxml” creationComplete=“init()”
layout=“absolute”>
<mx:Script>
<![CDATA[
import mx.collections.ArrayCollection;

        public var myArr:ArrayCollection = new ArrayCollection(new Array("1","2","3","4","5"));
        
        public var myTest:ArrayCollection = new ArrayCollection()
        
        public function init():void{
            myTest = new ArrayCollection(myArr.source);
            myTest.removeItemAt(2);
            trace(myTest.length);
            trace(myArr.length);
        }
    ]]&gt;
&lt;/mx:Script&gt;

</mx:Application>

the code above results in an output of

Code:

4
4

But I want it to result in
Code:

4
5

I believe that because you are pointing it to the arrayCollection’s source it isn’t making a new instance of that source, it is using the same source for both arrays, so when you change one both arraycollections change. Change the line to:

myTest = new ArrayCollection(myArr.toArray());

and that should work.

i’ll give it a go!

but why doesn’t this occure with Strings for example??

thanks!!