# attachMovie with variable name?

**URL:** <https://forum.kirupa.com/t/attachmovie-with-variable-name/220854>\
**Category:** flash\
**Created:** [March 29, 2007, 9:29pm UTC](https://forum.kirupa.com/t/attachmovie-with-variable-name/220854 "2007-03-29T21:29:02Z")\
**Posts on this page:** 1\
**Page:** 1

<div class="post-metadata">

**Author:** ![grenouille](https://avatars.discourse-cdn.com/v4/letter/g/f6c823/32.png) [@grenouille](https://forum.kirupa.com/u/grenouille)\
**Post date:** [March 29, 2007, 9:29pm UTC](https://forum.kirupa.com/t/attachmovie-with-variable-name/220854/1 "2007-03-29T21:29:02Z")

</div>

Hi,

does anyone know why this function is working fine (as long as I use the function only once - but the reason for that I get)

```auto

 
function CreateThumb(file,xp,yp,level)
{
 _root.attachMovie("img_holder","img_holder", level);
 img_holder._x = xp; 
 img_holder._y = yp; 
 img_holder.createEmptyMovieClip("img",1);
 img_holder.img.loadMovie(file);
 img_holder.onEnterFrame = function()
 {
  if(this.img.getBytesLoaded() >= this.img.getBytesTotal() && this.img.getBytesLoaded()>0) 
  {
   this.img._width = 15;
   this.img._height = 15;
   delete this.onEnterFrame;
  }
 }
}
 
CreateThumb("images/MAAT.JPG",100,100,1);

```

and why this one doesn’t - I simply used a variable for the attached movieclip

```auto

function CreateThumb(mcname, file,xp,yp,level)
{
 _root.attachMovie("img_holder",mcname, level);
 mcname._x = xp; 
 mcname._y = yp; 
 mcname.createEmptyMovieClip("img",1);
 mcname.img.loadMovie(file);
 mcname.onEnterFrame = function()
 {
  if(this.img.getBytesLoaded() >= this.img.getBytesTotal() && this.img.getBytesLoaded()>0) 
  {
   this.img._width = 15;
   this.img._height = 15;
   delete this.onEnterFrame;
  }
 }
}
 
CreateThumb2("newname", "images/MAAT.JPG",100,100,1);

```

I think the code itself is self-explanatory, so I won’t add any comments on that at this point.

It’s really irritating having a head full off design ideas and meeting problems like this one 😏

Thanks in advance.
