# Problems with instances

**URL:** <https://forum.kirupa.com/t/problems-with-instances/268673>\
**Category:** Uncategorized\
**Created:** [August 17, 2008, 1:59am UTC](https://forum.kirupa.com/t/problems-with-instances/268673 "2008-08-17T01:59:09Z")\
**Posts on this page:** 1\
**Page:** 1

<div class="post-metadata">

**Author:** ![iceheavybranchs](https://avatars.discourse-cdn.com/v4/letter/i/a183cd/32.png) [@iceheavybranchs](https://forum.kirupa.com/u/iceheavybranchs)\
**Post date:** [August 17, 2008, 1:59am UTC](https://forum.kirupa.com/t/problems-with-instances/268673/1 "2008-08-17T01:59:09Z")

</div>

i’m making a game in which the user can select items off a scrolling menu, drag them around, and delete them if they so choose by clicking a delete button. i’m new to as3 but have been able to figure out the rest of the code. the problem i am having now has to do with the instances of the items in the scrolling panel. i cannot get multiple instances of an item on the stage, and i cannot get them to drag independently of one another. when i try to use the delete button, i get error # 2007:parameter child must be non-null. what’s going on? i’ve been stuck on this for a few weeks and any help would be greatly appreciated. here’s the code:

MovieClip(scroller.content).str1cane\_mc.buttonMode = true;  
MovieClip(scroller.content).str1cane\_mc.addEventListener(MouseEvent.CLICK, straightCane1);

var str1cane:MovieClip = new straightcane1;

function straightCane1(e:MouseEvent):void {

```
var str1cane:MovieClip = new straightcane1;

for (var i:int = 1; i &lt; str1cane.numChildren + 1; i++) {

    container.addChild(str1cane);
    str1cane.name = "StraightCane" + i;
    str1cane.label = str1cane.name;
    str1cane.x = 300;
    str1cane.y = 225;

    container.addEventListener(MouseEvent.MOUSE_DOWN, moveStraightCane1);

    function moveStraightCane1(e:MouseEvent):void {
        container.addEventListener(MouseEvent.MOUSE_MOVE, makeStr1caneGo);

        function makeStr1caneGo(e:MouseEvent):void {

            for (var j:int = 1; j &lt;=str1cane.numChildren; j++) {
                
                function goodX(x:Number):Number {
                    if (x &lt; 0 + str1cane.width / 2) {
                        return 0 + str1cane.width / 2;
                    }
                    if (x &gt; 600 - str1cane.width / 2) {
                        return 600 - str1cane.width / 2;
                    }
                    return x;
                }
                function goodY(y:Number):Number {
                    if (y &lt; 0 + str1cane.height / 2) {
                        return 0 + str1cane.height / 2;
                    }
                    if (y &gt; 450 - str1cane.height / 2) {
                        return 450 - str1cane.height / 2;
                    }
                    return y;
                }
                str1cane.x = goodX(container.mouseX);
                str1cane.y = goodY(container.mouseY);
                e.updateAfterEvent();
                
                container.addEventListener(MouseEvent.MOUSE_UP, dropStraightCane1);
            }
        }
        
        

        function dropStraightCane1(e:MouseEvent):void {
            container.removeEventListener(MouseEvent.MOUSE_MOVE, makeStr1caneGo);
        }
        
        remove_mc.addEventListener(MouseEvent.CLICK, removeStraightCane1);

        function removeStraightCane1(e:MouseEvent):void {
            str1cane.addEventListener(MouseEvent.CLICK, goCane1);

            function goCane1(e:MouseEvent):void {
                container.removeEventListener(MouseEvent.MOUSE_DOWN, moveStraightCane1);
                container.removeEventListener(MouseEvent.MOUSE_UP, dropStraightCane1);
                container.removeEventListener(MouseEvent.MOUSE_MOVE, makeStr1caneGo);

                container.removeChild(container.str1cane);
            }
        }
    }
}

```

}
