A Flash Developer Resource Site

Results 1 to 3 of 3

Thread: removeChild question

  1. #1
    Junior Member
    Join Date
    Mar 2010
    Posts
    6

    removeChild question

    Hello,
    I'm trying to remove set of checkboxes from the stage once I move to the frame "providers" (you can see gotoAndStop "providers" at the very bottom of the code). I understand that removeChild would be used to do this, but I can't seem to figure out the syntax (perhaps it's different because the checkboxes are created with an array).

    Any help would be much appreciated!


    Code:
    import fl.controls.CheckBox;
    
    var checkBoxes:Array = new Array(0);
    
    var labels:Array = ["I use my phone primarily to make calls.", "I do a lot of text messaging, so I need a QWERTY keyboard.", "I want to be able to update my social media accounts.", "I want to be able to check my e-mail.", "I live in an area that has good 3G support.", "I want the full, HTML-based Web.", "I want to be able to connect to Wi-Fi hotspots.", "I want the latest and greatest mobile apps."]
    var lastY:int = 250;
    var OFFSET:int = 20;
    
    var tmpCheckBox:CheckBox;
    for (var i:int = 0; i < labels.length; i++) {
    	tmpCheckBox = new CheckBox;
    	tmpCheckBox.x = 330;
    	tmpCheckBox.width = 350;
    	lastY = lastY + OFFSET;
    	tmpCheckBox.y = lastY;
    	tmpCheckBox.label = labels[i];
    	checkBoxes.push(tmpCheckBox);
    	addChild(tmpCheckBox);
    }
    
    submit_btn.addEventListener(MouseEvent.CLICK, tallyEmUp);
    
    function checkABox(theBox:CheckBox):int {
        if(theBox.selected == true) {
            return 1;
        } else {
            return 0;
        }
    }
    
    function tallyEmUp(event:MouseEvent):void {
        var tally:int = 0;
            
    	for (var i:int = 0; i < checkBoxes.length; i++) {
    		var aCheckBox = checkBoxes[i];
    		tally = tally + checkABox(aCheckBox);
    	}
    	if (tally >= 4){
    		gotoAndStop("providers");
    	}
    }

  2. #2
    :
    Join Date
    Dec 2002
    Posts
    3,518
    Code:
    for (var i:int = 0; i < checkBoxes.length; i++) {
    	var aCheckBox=checkBoxes[i];
    	tally=tally+checkABox(aCheckBox);
    	removeChild(aCheckBox);
    }

  3. #3
    Junior Member
    Join Date
    Mar 2010
    Posts
    6

    Thumbs up It worked!

    Once again, dawson, you have saved me from my own newbness. I was trying to put remove child inside the conditional statement (if (tally >= 4)), but that didn't work.

    I can't say I totally understand why this works, but it does. Thanks again!

Posting Permissions

  • You may not post new threads
  • You may not post replies
  • You may not post attachments
  • You may not edit your posts
  •  




Click Here to Expand Forum to Full Width

HTML5 Development Center