jeudi 25 février 2016

using Action Script 3 remove an object that appeared in the run time

I use this code to create list of words from an array and make them act like buttons in the main page i have 2 buttons that activate the for loop to create the list of words the problem is when i hit the second button in the main the list of words of the first button still shown on the screen, i need to remove the list first then activate the second loop i used the removeChildAt() function but it didn't worked what should i do ?

var words:Array = [];
var word:MovieClip=new MovieClip();

if(e.target.name=="glossumbolA"){

words=['School1','School2','School3','School4','School5','School6']

for (var j:int = 0; j < words.length; j++)
{
    word = createTextButton(words[j]);
        addChild(word);
    word.addEventListener(MouseEvent.CLICK, wordButtonClick);
}
}



else if(e.target.name=="glossumbolB"){

words=['Class1','Class2']

for (var i:int = 0; i < words.length; i++)
{

     word = createTextButton(words[i]);
     addChild(word);
     word.addEventListener(MouseEvent.CLICK, wordButtonClick);
}

    }


function createTextButton(){

//code to make the word in the array a button

}

function wordButtonClick(){

//code to make an action when the word in the array clicked
} 

Aucun commentaire:

Enregistrer un commentaire