# removeChild Problem

**URL:** https://forum.kirupa.com/t/removechild-problem/276937
**Category:** Uncategorized
**Created:** [December 5, 2008, 6:57am UTC](https://forum.kirupa.com/t/removechild-problem/276937 "2008-12-05T06:57:34Z")
**Posts on this page:** 1
**Page:** 1

<div class="post-metadata">

### Author: ![Pherank](https://avatars.discourse-cdn.com/v4/letter/p/4af34b/32.png) [@Pherank](https://forum.kirupa.com/u/Pherank)
#### Post date: [December 5, 2008, 6:57am UTC](https://forum.kirupa.com/t/removechild-problem/276937/1 "2008-12-05T06:57:34Z")

</div>

I could use some help figuring out why I can’t remove the movieclip named “feedbackBox\_mc” when my dragCard function is called:

```auto

package {

    import flash.display.*;
    import flash.text.*;
    import flash.text.TextFormat;
    import flash.events.*;
    import flash.net.URLLoader;
    import flash.net.URLRequest;
    import flash.net.navigateToURL;
    import flash.utils.*;

    public class Drag_and_Drop extends MovieClip {

        // Movie Clips
        private var activeCard_mc:MovieClip;
        private var target_mc:MovieClip;
        private var feedbackBox_mc:MovieClip;
        private var messageSprite:Sprite;
        private var messageField:TextField;

        // Text Formats
        private var messageFormat:TextFormat;

        public function Drag_and_Drop() {

            // Attach draggable cards to stage
            for (var i:Number=numberOfCards; i>0; i--) {
                activeCard_mc = new ActiveCard;
                //activeCard_mc.name = "activeCard_" + (i + 1); // If counting up
                activeCard_mc.name = "activeCard_" + i;
                activeCard_mc.correctTarget = "target_" + cardArr[i - 1].correctTarget;
                activeCard_mc.statement = cardArr[i - 1].statement;
                activeCard_mc.correctFeedback = cardArr[i - 1].correctFeedback;
                activeCard_mc.incorrectFeedback = cardArr[i - 1].incorrectFeedback;

                activeCard_mc.mouseChildren = false;// May not need
                addChild(activeCard_mc);

                activeCard_mc.x = xVal;
                activeCard_mc.y = yVal;
                xVal = activeCard_mc.x - this.cardXOffset;
                yVal = activeCard_mc.y - this.cardYOffset;

                activeCard_mc.buttonMode = true;
                activeCard_mc.mouseChildren = false;
                activeCard_mc.addEventListener(MouseEvent.MOUSE_DOWN, dragCard);
                activeCard_mc.addEventListener(MouseEvent.MOUSE_UP, stopDragCard);
            }

        public function dragCard(event:MouseEvent):void {

            if (feedbackBox_mc != null) {
                // NOTHING HAPPENS HERE
                trace(feedbackBox_mc.x);
                removeChild(feedbackBox_mc);
                removeChild(messageField);
            }
        }
        public function stopDragCard(event:MouseEvent):void {
            event.target.stopDrag();
            displayFeedback(1,event.target.correctFeedback);
        }
        // Creates a text field
        public function createText(text:String,tf:TextFormat,s:Sprite,x,y:Number,width:Number):TextField {

        }
        public function displayFeedback(goToFrame:Number,feedbackText:String):void {

            // Add feedbackBox from Library
            var feedbackBox_mc:feedbackBox = new feedbackBox;
            feedbackBox_mc.x = 682;
            feedbackBox_mc.y = 158;
            feedbackBox_mc.name = "feedbackBox_mc";
            addChild(feedbackBox_mc);
            var addFeedbackShadow = new DropShadow(feedbackBox_mc,8,8,1,1,0x000000,.70,45,3,false,false,false);
            feedbackBox_mc.gotoAndStop(goToFrame);
            // prepare new message sprite
            messageSprite = new Sprite;
            messageFormat = new TextFormat(arialFont.fontName,14,0x333333,false,false,false,null,null,"left");
            messageFormat.leading = 2;
            messageField = createText(feedbackText,messageFormat,messageSprite,xPos,yPos,429);
            messageField.alpha = 0;
            addChild(messageSprite);
        }
    }
}

```

Note that I removed all kinds of extraneous code to concentrate on this issue. One thing I don’t get is the conditional

```auto
feedbackBox_mc != null

```

seems to make the compiler happy but I can’t get any reference to the feedbackBox\_mc to work. Thanks for your help.
