# Loop overwriting itself

**URL:** <https://forum.kirupa.com/t/loop-overwriting-itself/257653>\
**Category:** Uncategorized\
**Created:** [April 16, 2008, 1:38am UTC](https://forum.kirupa.com/t/loop-overwriting-itself/257653 "2008-04-16T01:38:12Z")\
**Posts on this page:** 1\
**Page:** 1

<div class="post-metadata">

**Author:** ![nukegara](https://avatars.discourse-cdn.com/v4/letter/n/71c47a/32.png) [@nukegara](https://forum.kirupa.com/u/nukegara)\
**Post date:** [April 16, 2008, 1:38am UTC](https://forum.kirupa.com/t/loop-overwriting-itself/257653/1 "2008-04-16T01:38:12Z")

</div>

what do you do when a loop “overwrites” itself and only displays the last value?

```auto
for ( var j:Number = 0; j < xml_array.length; j++ ) {
        
            //Set state movie clips' parentMC and mainBroadcaster and onRelease functions
            this ["state" + j + "_mc"].mainBroadcaster = this.mainBroadcaster;
            this ["state" + j + "_mc"]._alpha = 0;
            this ["state" + j + "_mc"].stateID = idArray[j];
            this ["state" + j + "_mc"].onRollOver = function() {
                //when clicked, tell button to broadcast its id
                this.mainBroadcaster.broadcastMessage( "stateRolled", stateID, this );
                trace("state " + j + " was rolled over. For the Greater Good.");
            }
        }

```

here is the code snippet for the loop; I’ve used this before in a previous project and it didn’t have this problem.

Thanks~ :kir:
