Search code examples
arraysactionscript-3indexingaddchild

as3 using addChild with an array containing indexes


so i have an array containing many instances. let's say movieclips.

and i have another array which contains numbers..in this case those numbers represent selected indices that i've somehow chosen!

var manydots:Array = new Array ();

for (var i=0; i<10; i++)
{
    var newDot:dot = new dot  ;
    manydots.push(newDot);
}

var indices:Array = [0,1,5,8,4]

i want to use AddChild to add those movieclips into my scene, but not all of them, only selected indices contained in my 2nd array


Solution

  • I think this is what you are looking for,

    for (var j=0; j<indicies.length; j++) {
        addChild(manyDots[incidies[j]]);
    }