addChild() method doesn't work properly

148 Views Asked by At

I'm trying to print some images on the stage but something goes wrong during collaudes, not all the images are printed, i traced them to verify if they exist, and they do, I verified they also have proper coordinates, and they do... You just can't see them... why? validFaces is an array containing some bitmaps, OXA is an array containing some Points, their coordinates should be parrallel as i've done... Why sometimes some of them are invisible?

function printOpponents():void{
    for (var k:int = 0; k<numOpp; k++){
        addChild(validFaces[k]);
        validFaces[k].x = OXA[k].x;
        validFaces[k].y = OXA[k].y;

    }
}
2

There are 2 best solutions below

14
On

Try making them above the highest index:

function printOpponents():void{
    for (var k:int = 0; k<numOpp; k++){
        addChild(validFaces[k]);
        validFaces[k].x = OXA[k].x;
        validFaces[k].y = OXA[k].y;
        validFaces[k].parent.setChildIndex(validFaces[k], validFaces[k].parent.numChildren - 1);
    }
}

validFaces[k].parent gets the the parent of validFaces[k] and setChildIndex sets the level it should be (ex: one object is shown above another) validFaces[k].parent.numChildren - 1 gets the Object at the highest index, therefore making validFaces[k] the Object that is on top of all others (validFaces[numOpp - 1] is technically on top of all others).

0
On

I successfully fixed the problem, there was a semantic wrong function in another frame, so the array validFaces used to contain images and numbers, i fixed it declaring a new array validFacesImages cointaining all the images, and now it works ;) thank you.