mardi 30 juin 2015

How to removechild in as3?

this is my code:

var star:Sprite = new Sprite();
for (var i:Number = 0; i<50; ++i) //check if sky contains star , remove them
{
     if (sky.contains(star)) //this "if" didnt work!
     {
        sky.removeChild(star);
     }
}
for (i= 0; i<50; ++i) //add new stars to sky
{
    star = new Sprite();
    star.graphics.beginFill(0xFFFFFF);
    star.graphics.drawCircle(0, 0, ((Math.random() * 1.5) + 0.25));
    star.x = Math.random() * stage.stageWidth ;
    star.y = Math.random() * stage.stageHeight;
    sky.addChild(star);
}

the 1st "if" didnt work and in 2nd "for" stars add to sky over previous stars! what is the correct code to remove previous stars?thanks

Aucun commentaire:

Enregistrer un commentaire