# A counting problem

**URL:** <https://forum.kirupa.com/t/a-counting-problem/204931>\
**Category:** Uncategorized\
**Created:** [October 24, 2006, 6:47pm UTC](https://forum.kirupa.com/t/a-counting-problem/204931 "2006-10-24T18:47:43Z")\
**Posts on this page:** 1\
**Page:** 1

<div class="post-metadata">

**Author:** ![Navarone](https://avatars.discourse-cdn.com/v4/letter/n/f9ae1b/32.png) [@Navarone](https://forum.kirupa.com/u/Navarone)\
**Post date:** [October 24, 2006, 6:47pm UTC](https://forum.kirupa.com/t/a-counting-problem/204931/1 "2006-10-24T18:47:43Z")

</div>

I have swf being loaded onto the stage. Currently the count varies because of the getNextHighestDepth. I am trying to get the count to increment by 1, but when I do, and I add a new item replaces the existing item, which I don’t want. How can I get around this?

```auto

//_global.count = 0;
function newPiece() {
 // create a movieclip to hold the functionality of the peice of furniture
 // keep all the furniture inside 1 clip (called 'pieceContainer') for organizational purposes
 var count:Number = pieceContainer.getNextHighestDepth();
 var item_mc:MovieClip = pieceContainer.createEmptyMovieClip("item_mc"+count, count);
 trace(count);
 // create a container to load the furniture swf into
 var container:MovieClip = item_mc.createEmptyMovieClip("container_mc", 0);
 container._x = 0;
 container._y = 0;
 // setup a MCL to handle the swf's loading, when its loaded, apply the freeTransform methods to it. 
 item_mc.mcl = new MovieClipLoader();
 item_mc.mcl.addListener(mclListener_2);
 item_mc.mcl.loadClip("decals/"+this.piece+".swf", container);
 //
 //count++;
}
//
var mclListener_2:Object = new Object();
mclListener_2.onLoadInit = function(mc:MovieClip) {
 // set variables to remember the original dimensions
 var axw = mc._width;
 var axh = mc._height;
 //trace(axw);
 //trace(axh); 
 // center piece  
 mc._y = -(axh/2);
 mc._x = -(axw/2);
 //
 //add rotation and drag properties 
 mc._parent.onPress = function() {
  this.addFreeTransform();
  trace(mc._parent);
 };
 // 
};

```
