# Problem with attachMovie in for loop - flash 8 (as2)

**URL:** <https://forum.kirupa.com/t/problem-with-attachmovie-in-for-loop-flash-8-as2/255576>\
**Category:** Uncategorized\
**Created:** [March 24, 2008, 10:44pm UTC](https://forum.kirupa.com/t/problem-with-attachmovie-in-for-loop-flash-8-as2/255576 "2008-03-24T22:44:11Z")\
**Posts on this page:** 1\
**Page:** 1

<div class="post-metadata">

**Author:** ![jargon12](https://avatars.discourse-cdn.com/v4/letter/j/ec9cab/32.png) [@jargon12](https://forum.kirupa.com/u/jargon12)\
**Post date:** [March 24, 2008, 10:44pm UTC](https://forum.kirupa.com/t/problem-with-attachmovie-in-for-loop-flash-8-as2/255576/1 "2008-03-24T22:44:11Z")

</div>

Hello everyone,

I seem to be having a bit of trouble with my code- specifically the attachMovie line in the for loop below. I have a series of movieclips with identifiers named “loc\_1”, “loc\_2”, “loc\_3” … which are supposed to load inside the scrollPane which is located on the root timeline.

I think I have the problem narrowed down to the first parameter in attachMovie :  
mcMain.attachMovie( **“loc\_”+i** , “loc\_”+i, mcMain.getNextHighestDepth());

If I change it to “loc\_1” instead of “loc\_”+i, it loads the movie clip…

Here’s what the AS looks like:

```auto

stop();

var mcMain:MovieClip;
var i:Number=0;

function init() {
    scrollPane.contentPath = "scrollMovieClip";
    mcMain = scrollPane.content;
    //trace(mcMain);
}

init();

for( i = 1; i <= 9; i++) {
    _root["loc_" + i].onRelease = function (){
    mcMain.attachMovie("loc_"+i, "loc_"+i, mcMain.getNextHighestDepth());
    scrollPane.invalidate();
    }
}

```

Any help is greatly appreciated 🙂

Thanks
