Skip to main content
Known Participant
July 10, 2013
Answered

I can addChild movieClip using check box, but how do you removeChild when box is unchecked?

  • July 10, 2013
  • 1 reply
  • 1671 views

I will have 8 check boxes on this screen. I want the user to check any number or all boxes to see a line on a graph. I also want them to be able to uncheck the selected box to remove the line. Each box calls a certain line to the stage.

I can get the line to show up when checked, but not dissappear when unchecked.

I also want to have a check box to select all lines on the screen.

var graph:hp455mt_mc = new hp455mt_mc();

box455.addEventListener(MouseEvent.CLICK, clickHandler);

function clickHandler(evt:MouseEvent):void {

  addChild(graph);
graph.x = 179;
graph.y = 22.35;     
}

This topic has been closed for replies.
Correct answer Ned Murphy

You can use the same function and within it have a conditional to check if the box selected property is true... if it is then you add the child and if it is false you remove the child.

....

   if(box455.selected){

        addChild(etc...

   } else {

        removeChild(etc....

   }

1 reply

Ned Murphy
Ned MurphyCorrect answer
Legend
July 10, 2013

You can use the same function and within it have a conditional to check if the box selected property is true... if it is then you add the child and if it is false you remove the child.

....

   if(box455.selected){

        addChild(etc...

   } else {

        removeChild(etc....

   }

Known Participant
July 10, 2013

Thanks! This is a great help.

Known Participant
July 11, 2013

If you need all of the lines added when the page loads then just loop thru creating them and add them all at once.

What you might consider instead of using add/removeChild is to just addChild all of them at the start and from there on out control their visible property instead.  Going that way you won't run the risk of trying to remove a child that has not been added yet.


Ned,

Great idea. I am more of a Timeline guy-those designers- so I don't no all the ins and outs of the AS3 side. I will research the visibility property.Thanks for taking the time.

Randy