Exit
  • Global community
    • Language:
      • Deutsch
      • English
      • Español
      • Français
      • Português
  • 日本語コミュニティ
  • 한국 커뮤니티
0

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

Community Beginner ,
Jul 10, 2013 Jul 10, 2013

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;     
}

TOPICS
ActionScript
1.6K
Translate
Report
Community guidelines
Be kind and respectful, give credit to the original source of content, and search for duplicates before posting. Learn more
community guidelines

correct answers 1 Correct answer

LEGEND , Jul 10, 2013 Jul 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....

   }

Translate
LEGEND ,
Jul 10, 2013 Jul 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....

   }

Translate
Report
Community guidelines
Be kind and respectful, give credit to the original source of content, and search for duplicates before posting. Learn more
community guidelines
Community Beginner ,
Jul 10, 2013 Jul 10, 2013

Thanks, I am trying to figure that part out now.

Translate
Report
Community guidelines
Be kind and respectful, give credit to the original source of content, and search for duplicates before posting. Learn more
community guidelines
Community Beginner ,
Jul 10, 2013 Jul 10, 2013

Thanks! This is a great help.

Translate
Report
Community guidelines
Be kind and respectful, give credit to the original source of content, and search for duplicates before posting. Learn more
community guidelines
LEGEND ,
Jul 10, 2013 Jul 10, 2013

You're welcome

Translate
Report
Community guidelines
Be kind and respectful, give credit to the original source of content, and search for duplicates before posting. Learn more
community guidelines
Community Beginner ,
Jul 10, 2013 Jul 10, 2013

Ned,

Sorry to bother one more time. Now This graph sits on a web page. The checkboxes show and not show a line ion a graph. There are 9 lines.

I am now asked to have them all showing and boxes checked when you land on the page. Right now I can have all the boxes checked in Properties of the CheckBox but the graph line is not showing because there was no mouseClick for the eventListener to trigger from.

Can I even do this?

Translate
Report
Community guidelines
Be kind and respectful, give credit to the original source of content, and search for duplicates before posting. Learn more
community guidelines
LEGEND ,
Jul 10, 2013 Jul 10, 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.

Translate
Report
Community guidelines
Be kind and respectful, give credit to the original source of content, and search for duplicates before posting. Learn more
community guidelines
Community Beginner ,
Jul 11, 2013 Jul 11, 2013

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

Translate
Report
Community guidelines
Be kind and respectful, give credit to the original source of content, and search for duplicates before posting. Learn more
community guidelines
LEGEND ,
Jul 11, 2013 Jul 11, 2013

You're welcome - just to clarify - it is the "visible" property, not "visibility".

Translate
Report
Community guidelines
Be kind and respectful, give credit to the original source of content, and search for duplicates before posting. Learn more
community guidelines
Community Beginner ,
Jul 11, 2013 Jul 11, 2013

Ok, I did this:

var graph:hp485mc = new hp485mc();

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

var graph1:hp380_mc = new hp380_mc();

addChild(graph1);
graph1.x = 179;
graph1.y = 22.35;


var graph2:hp485mc = new hp485mc();

cb485.addEventListener(MouseEvent.CLICK, clickHandler2hp);

function clickHandler2hp(event:MouseEvent):void {

if(graph.visible){
    graph.visible = false;
}
}

And it loads right away, and dissappears when the check box is unchecked(clicked) but when I added this to make it appear :

cb485.addEventListener(MouseEvent.CLICK, clickHandler2hp);

function clickHandler2hp(event:MouseEvent):void {

if(graph.visible){

    graph.visible = false;

}if

(!graph.visible){

    graph.visible = true;

}

}

It doesn't appear or dissappear. How do I get the check box to control it again?

Wait-just figured it out:

var graph2:hp485mc = new hp485mc();

cb485.addEventListener(MouseEvent.CLICK, clickHandler2hp);

function clickHandler2hp(event:MouseEvent):void {

if(graph.visible){
    graph.visible = false;
}else
{
    graph.visible = true;
}
}

This works!

Translate
Report
Community guidelines
Be kind and respectful, give credit to the original source of content, and search for duplicates before posting. Learn more
community guidelines
LEGEND ,
Jul 11, 2013 Jul 11, 2013

You want to use an if/else.  What you did was to create 2 if's where teh first makes the second always make it visible... rewritten below to see it morew clearly

if(graph.visible){

    graph.visible = false;   // makes it invisible

}  

if(!graph.visible){  // it is invisible whether you intended it to be or not

    graph.visible = true;  // so make it visible

}

it should be:

if(graph.visible){

    graph.visible = false;

} else {   // no need to test the opposite - if it isn't true, it's false

    graph.visible = true;

}

But you could actually just toggle the value of the visible property instead of using a conditional... tell it to be the opposite of what it is...

function clickHandler2hp(event:MouseEvent):void {

    graph.visible = !graph.visible;

}

Translate
Report
Community guidelines
Be kind and respectful, give credit to the original source of content, and search for duplicates before posting. Learn more
community guidelines
Community Beginner ,
Jul 11, 2013 Jul 11, 2013

Very cool! Thanks!

Translate
Report
Community guidelines
Be kind and respectful, give credit to the original source of content, and search for duplicates before posting. Learn more
community guidelines
LEGEND ,
Jul 11, 2013 Jul 11, 2013
LATEST

You're welcome

Translate
Report
Community guidelines
Be kind and respectful, give credit to the original source of content, and search for duplicates before posting. Learn more
community guidelines