dimanche 11 décembre 2016

Send all instances of a container BEHIND everything else?

Found this topic: AS3 setChildIndex to front and I have no idea why, but for some weirdly illogical reason I can edit other peoples' posts but I can't comment on other peoples' question answers... what? Anyway, the question here is similar to that of this, just that I'm trying to accomplish the exact opposite, but since I can't comment on it and need goddamn 50 reputation, I had to ask a new question.

Anyway, to the problem. "addChildAt" doesn't work for me when I'm setting the container behind everything else or something along the lines. And as for stars themselves, I can't send them back anymore than layer 0 for some odd reason (it'll give me error 2006, stating "The supplied index is out of bounds"). Here's the code:

starsSpawn function:

var starContainer:MovieClip = new MovieClip();
addChildAt(starContainer, 20);

starContainer code:

function starsSpawn()
{
    for(var i:int= 0; i < 30; i++)
    {
        var newStar = new starCode();
        var scaleXY = Math.random()*(2)+0.1;
        newStar.width = scaleXY;
        newStar.height = scaleXY;
        var positionX:Number = Math.random()*(stage.stageWidth + (1* newStar.width));
        var randomY:Number = Math.random()*(stage.stageHeight - newStar.height);
        newStar.x = positionX;
        newStar.y = randomY;
        starContainer.addChild(newStar);
    }
}

Essentially how it works is that a container is set up and the for loop creates 30 stars, each with the outlined code.

Aucun commentaire:

Enregistrer un commentaire