Skip to main content
dalvydasv27776233
Inspiring
January 8, 2016
Question

AS3 How to remove childrens?

  • January 8, 2016
  • 3 replies
  • 2397 views

Hey, I have script for adding childrens. Then I want to remove childs everything in scene dissapears and I see just blank screen.

This is my code:

function answerF(answerS:String,x:int,y:int,space:int):void{

var raides:int = answerS.length;

var word:int;

if ((answerS.length % 2) == 0){

    word = (((raides * 150) + ((raides - 1) * space))/2 - 150);

} else {

    word = ((((raides -1) * 150) + ((raides - 1) * space))/2)-75;   

}

var nextX:int = x - word;

var C:Class;

var letter:MovieClip;

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

C=Class(getDefinitionByName(answerS.charAt(i)));

letter=new C();

addChild(letter);

letter.x=nextX;

letter.y=y;

nextX+=letter.width+space;

}

}

So how i can remove just theese childrens? Please help.

This topic has been closed for replies.

3 replies

dalvydasv27776233
Inspiring
January 11, 2016

function removeF():void{

for(var i:int=answerA.numChildren-1;i>=0;i--){

if(answerA.stage){

removeChild(answerA);

}

}

}

function removeF():void{

for(var i:int=answerA.length-1;i>=0;i--){

if(answerA.stage){

removeChild(answerA);

}

}

}

Thanks for everyone who help me removeF() works

robdillon
Participating Frequently
January 11, 2016

I spent some time looking through your file. I don't really understand what you are attempting here. You are importing two text files. You put up a series of rectangles with text letters over each one. One sound plays if you get a letter correct and a different sound plays if the letter typed is incorrect. The rectangles and the text are each separate objects that are placed on the stage.

I'm guessing that you want to remove the existing rectangles and text when a word is completed and then start with a new word.

The way that your movie is laid out on the timeline and the code that you have show that you have a collection of bits and pieces from many sources. These pieces and the overall design don't work well together. You really need to diagram what you want this file to do, then define your objectives.

dalvydasv27776233
Inspiring
January 11, 2016

Yes I know it, but Im working how I understand. From this file I want much more than can so without help I cant do this. Sometimes with PRO help difficult to understand what to do or say what I want to do becouse of my English.

In this file I have a question from txt file. The question uploads in dynamic text field. In next frame  have answer (add letter child from library). When the word is completed I have Second question and in the other frame answer and so on. It is just test file for trying understand how it works. All project will be the party game. In action script fields I think will be "salad" becouse I dont know other ways to do it.

dalvydasv27776233
Inspiring
January 9, 2016

Maby someone can help me?

dalvydasv27776233
Inspiring
January 10, 2016

please?

robdillon
Participating Frequently
January 10, 2016

From looking at the code that you've supplied in the messages above, I'm guessing that you've done previous work in AS1/2. Laying out a bunch of individual commands on frames will work, sort of, in AS3, but it's not efficient and can cause more problems than it solves. What would be very useful to anyone giving assistance is to see the whole movie file along with a detailed description of what you expect the project to do.

That being said, it sounds as if you need a lot of work. It is really outside the scope of this forum to provide a custom tutorial for Flash that will get your project completed. Most anyone on the forum will gladly assist you in finding a solution to a specific problem, you would be best served by re-thinking the programatic design of your project. In order to do that you will need to share with the forum what you have in mind.

kglad
Community Expert
Community Expert
January 8, 2016

again, one of the ways is to use an array to save those children (for later removal):

var answerA:Array=[];

function answerF(answerS:String,x:int,y:int,space:int):void{

var raides:int = answerS.length;

var word:int;

if ((answerS.length % 2) == 0){

    word = (((raides * 150) + ((raides - 1) * space))/2 - 150);

} else {

    word = ((((raides -1) * 150) + ((raides - 1) * space))/2)-75;  

}

var nextX:int = x - word;

var C:Class;

var letter:MovieClip;

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

C=Class(getDefinitionByName(answerS.charAt(i)));

letter=new C();

addChild(letter);

answerA.push(letter);

letter.x=nextX;

letter.y=y;

nextX+=letter.width+space;

}

}

// then whenever you want to remove those letters, call removeF()

function removeF():void{

for(var i:int=answerA.numChildren=1;i>=0;i--){

removeChild(answerA);

}

}

dalvydasv27776233
Inspiring
January 8, 2016

Not working

kglad
Community Expert
Community Expert
January 8, 2016

show the code you used to remove those letters.