# Making this into a loop problem

**URL:** <https://forum.kirupa.com/t/making-this-into-a-loop-problem/175778>\
**Category:** flash\
**Created:** [January 17, 2006, 7:32pm UTC](https://forum.kirupa.com/t/making-this-into-a-loop-problem/175778 "2006-01-17T19:32:17Z")\
**Posts on this page:** 1\
**Page:** 1

<div class="post-metadata">

**Author:** ![mprzybylski](https://yyz1.discourse-cdn.com/flex011/user_avatar/forum.kirupa.com/mprzybylski/32/613_2.png) [@mprzybylski](https://forum.kirupa.com/u/mprzybylski)\
**Post date:** [January 17, 2006, 7:32pm UTC](https://forum.kirupa.com/t/making-this-into-a-loop-problem/175778/1 "2006-01-17T19:32:17Z")

</div>

Hello,  
I have the following code, which works normally on its own:

```auto
tRef.vid1Listener.ready = function():Void {
        tRef.vid1_mc.vid.seekSeconds(tRef.cp1Time);
    };
    
    tRef.vid1_mc.vid.addEventListener("ready", tRef.vid1Listener);

```

however, i have four of these listeners, so i just wanted to run a loop on it so that it works without having to write each separately. here is my loop, that doesnt work:

```auto
for (var i:Number = 1; i <= vidNum; i++) {
        var ob:Object = new Object();
        ob.id = i;
        
        // put movies at proper start times
        tRef["vid" + ob.id + "Listener"].ready = function():Void {
            if (ob.id < 4) {
                tRef["vid" + ob.id + "_mc"].vid.seekSeconds(tRef["cp" + ob.id + "Time"]);
            }
        };
        
        tRef["vid" + ob.id + "_mc"].vid.addEventListener("ready", tRef["vid" + ob.id + "Listener"]);
    }

```

i’ve done this like a million times but im having the hardest time figuring out why its not working. actually, i did pinpoint the problem, in that ob.id reads out as 4 on every iteration, but why is it not reading as 1, 2, 3, 4 like it should? i’m just having a terrible computer day so if anyone can help me with my brainfart, i’d greatly appreciate it. thanks.
