# MovieClip prototype, attachMovie and var

**URL:** https://forum.kirupa.com/t/movieclip-prototype-attachmovie-and-var/219882
**Category:** flash
**Created:** [March 20, 2007, 9:30pm UTC](https://forum.kirupa.com/t/movieclip-prototype-attachmovie-and-var/219882 "2007-03-20T21:30:05Z")
**Posts on this page:** 1
**Page:** 1

<div class="post-metadata">

### Author: ![bobllama](https://avatars.discourse-cdn.com/v4/letter/b/cc9497/32.png) [@bobllama](https://forum.kirupa.com/u/bobllama)
#### Post date: [March 20, 2007, 9:30pm UTC](https://forum.kirupa.com/t/movieclip-prototype-attachmovie-and-var/219882/1 "2007-03-20T21:30:05Z")

</div>

I’ve got a MovieClip.prototype function that loads an mc from the library using attachMovie. I want the mc to be loaded to be determined by a var that I determine based on which button is pressed.

It won’t work for some reason. It seems like the prototype won’t update the var in the attachmovie.

Example:

```auto
MovieClip.prototype.fadeIn = function() {
	i = 1;
	loadybox = _root.attachMovie(loadBox, "loadybox"+i, i);
}
var background:String = "back_1";
button1.onRelease = function() {
var background:String = this._name;

```

Obviously the buttons and backgrounds have the same name. I’ve tried adding in a

```auto
delete background

```

to the onRelease, but when I trace it it becomes undefined after deleting.

Any suggestions on how to set a variable to determine which mc will be loaded by button pressing?
