Skip to main content
dalvydasv27776233
Inspiring
April 20, 2018
Answered

Cant removeChilds

  • April 20, 2018
  • 2 replies
  • 738 views

Hey i have problem:

am adding childs with this code:

function show_time(){

    var i:int;

        for (i = 0; i < dataArray.length; i++){

            var kalendorius:MovieClip = new calendar;

            kalendorius.name = "data"+i;

            addChild(kalendorius);

            kalendorius.x = ix;

            kalendorius.y = iy;

            timeArray = dataArray.split(" - ");

            kalendorius.menuo.text = timeArray[0];

            kalendorius.diena.text = timeArray[1];

            kalendorius.savaites_diena.text = timeArray[2];

            kalendorius.time1.text = timeArray[3];

            kalendorius.time2.text = timeArray[4];

            kalendorius.patvirtinimas.text = timeArray[5];

            a++;

            iy=iy+335;

        }

}

Butt now I don`t understand why I cant remnove childs with this:

function reload_calendorius(){

    while (kalendorius.numChildren > 0) {

        kalendorius.removeChildAt(0);

    }

}

This topic has been closed for replies.
Correct answer JoãoCésar17023019

Hi.

You are adding this kalendorius Movie Clip to the main timeline. So they are children of the main timeline.

My advice is to add the kalendorius Movie Clips to a container and them remove them from the container.

Like this:

function show_time()

{

    // ...

    container.addChild(kalendorius);

    // ...

}

function reload_calendorius()

{

    while (container.numChildren > 0)

    {

        container.removeChildAt(0);

    }

}

Regards,

JC

2 replies

JoãoCésar17023019
Community Expert
JoãoCésar17023019Community ExpertCorrect answer
Community Expert
April 20, 2018

Hi.

You are adding this kalendorius Movie Clip to the main timeline. So they are children of the main timeline.

My advice is to add the kalendorius Movie Clips to a container and them remove them from the container.

Like this:

function show_time()

{

    // ...

    container.addChild(kalendorius);

    // ...

}

function reload_calendorius()

{

    while (container.numChildren > 0)

    {

        container.removeChildAt(0);

    }

}

Regards,

JC

dalvydasv27776233
Inspiring
April 20, 2018

I dont understand nothing about cointainers and i dont know how to write this script:|

JoãoCésar17023019
Community Expert
Community Expert
April 20, 2018

The 'container' is just a Movie Clip. It's the instance name I gave to it.

The idea is to add the objects to a single Movie Clip and then later on you remove the chidlren from this single Movie Clip you are using as a container.

Got it?

Ned Murphy
Legend
April 20, 2018

Based on what I see of your code, it will not remove any kalendorius object, though it could empty the last one out of whatever is in it.

To remove them, you likely need to be target them by their name (getChildByName()).

dalvydasv27776233
Inspiring
April 20, 2018

? removeChild(data1); removeChild(data2) and etc?

this not working too:)

Ned Murphy
Legend
April 23, 2018

Not intending to send you steps back at all, but for your reply (which I missed following up on)... names are Strings, so...

removeChild(getChildByName("data1"));

removeChild(getChildByName("data2"));