# Problem with dynamic text box

**URL:** <https://forum.kirupa.com/t/problem-with-dynamic-text-box/270458>\
**Category:** flash\
**Created:** [September 10, 2008, 8:22am UTC](https://forum.kirupa.com/t/problem-with-dynamic-text-box/270458 "2008-09-10T08:22:53Z")\
**Posts on this page:** 1\
**Page:** 1

<div class="post-metadata">

**Author:** ![ElmGoodie](https://avatars.discourse-cdn.com/v4/letter/e/3e96dc/32.png) [@ElmGoodie](https://forum.kirupa.com/u/ElmGoodie)\
**Post date:** [September 10, 2008, 8:22am UTC](https://forum.kirupa.com/t/problem-with-dynamic-text-box/270458/1 "2008-09-10T08:22:53Z")

</div>

Hey there!

Ok, so I’m pretty new to AS3, and I have a question.  
Here’s the code:

```php

import flash.filters.GlowFilter;

addEventListener(Event.ENTER_FRAME, createNewBox);
addEventListener(MouseEvent.MOUSE_DOWN, startTheDrag, false, 0, true);
addEventListener(MouseEvent.MOUSE_UP, stopTheDrag, false, 0, true);

const boxNum = 10;

var box:MovieClip;
var newBox:MovieClip;

var boxIndex:int;
var newBoxIndex:int = 0;

var alphaJump:Number = 1/(boxNum);
var oldAlpha:Number;

var glow:GlowFilter = new GlowFilter(0xFFCC00,1,26,26,1.3,3);

function createNewBox(evt:Event): void {
    if(newBoxIndex < boxNum) {
        
        var newBox:MovieClip = new BOX();
        addChildAt(newBox, newBoxIndex);

        with(newBox) {
            x = y = (newBoxIndex * 35) + 50;
            name = "box"+(newBoxIndex+1);
            labelz.text = name.toUpperCase();
            buttonMode = true;
            alpha = 0 + ((newBoxIndex+1) * alphaJump);
        }
        
        newBoxIndex++;
    }
}

function startTheDrag(evt:MouseEvent):void {

    box = evt.target as MovieClip;
    boxIndex = getChildIndex(box);
    setChildIndex(box, numChildren-1);
    box.gotoAndPlay(2);
    box.startDrag();
    box.filters = [glow];
    oldAlpha = box.alpha;
    box.alpha = 1;
}

function stopTheDrag(evt:MouseEvent):void {

    evt.target.stopDrag();
    box = evt.target as MovieClip;
    box.gotoAndPlay(11);
    setChildIndex(box, boxIndex);
    box.filters = null;
    box.alpha = oldAlpha;
}

```

If I click on the text label, instead of the box itself, I get the following error message:

> TypeError: Error #2007: Parameter child must be non-null.  
> at flash.display:DisplayObjectContainer/getChildIndex()  
> at boxes\_fla::MainTimeline/startTheDrag()  
> ReferenceError: Error #1069: Property stopDrag not found on flash.text.TextField and there is no default value.  
> at boxes\_fla::MainTimeline/stopTheDrag()

The text label is inside the target, so why am I not able to drag the object if I happen to click on the area of the textbox?

Thanks in advance,  
\*\*\*Confused newbie

* * *
