Copy link to clipboard
Copied
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;
}
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....
}
Copy link to clipboard
Copied
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....
}
Copy link to clipboard
Copied
Thanks, I am trying to figure that part out now.
Copy link to clipboard
Copied
Thanks! This is a great help.
Copy link to clipboard
Copied
You're welcome
Copy link to clipboard
Copied
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?
Copy link to clipboard
Copied
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.
Copy link to clipboard
Copied
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
Copy link to clipboard
Copied
You're welcome - just to clarify - it is the "visible" property, not "visibility".
Copy link to clipboard
Copied
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!
Copy link to clipboard
Copied
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;
}
Copy link to clipboard
Copied
Very cool! Thanks!
Copy link to clipboard
Copied
You're welcome
Find more inspiration, events, and resources on the new Adobe Community
Explore Now