# Button start MC

**URL:** https://forum.kirupa.com/t/button-start-mc/113361
**Category:** Uncategorized
**Created:** [June 17, 2004, 5:22am UTC](https://forum.kirupa.com/t/button-start-mc/113361 "2004-06-17T05:22:58Z")
**Posts on this page:** 8
**Page:** 1

<div class="post-metadata">

### Author: ![eze](https://avatars.discourse-cdn.com/v4/letter/e/e79b87/32.png) [@eze](https://forum.kirupa.com/u/eze)
#### Post date: [June 17, 2004, 5:22am UTC](https://forum.kirupa.com/t/button-start-mc/113361/1 "2004-06-17T05:22:58Z")

</div>

hey i use to have this code but i wasnt working -

```auto

button_array = ["home", "plans", "terms", "contact"];
for (var i in button_array) {
 btn = this[button_array*];
 btn.clip = this[button_array*]+"_mc";
 btn.onRelease = function() {
  _root.fromName = btn.clip;
  content_mc.gotoAndPlay(36);
 };
}

```

so i forced to change to individual onRelease functions -

```auto

home.onRelease = function() {
  _root.fromName = "home_mc"
  content_mc.gotoAndPlay(36);
 };
 
plans.onRelease = function() {
  _root.fromName = "plans_mc"
  content_mc.gotoAndPlay(36);
 };
 
terms.onRelease = function() {
  _root.fromName = "terms_mc"
  content_mc.gotoAndPlay(36);
 };
 
contact.onRelease = function() {
  _root.fromName = "contact_mc"
  content_mc.gotoAndPlay(36);
 };

```

---

<div class="post-metadata">

### Author: ![system](https://canada1.discourse-cdn.com/flex011/uploads/kirupa/original/3X/6/2/621e5c11736f46532526e61be85940af4230f3e5.png) [@system](https://forum.kirupa.com/u/system)
#### Post date: [June 17, 2004, 5:23am UTC](https://forum.kirupa.com/t/button-start-mc/113361/2 "2004-06-17T05:23:30Z")

</div>

anyone got a better way i could do something like the first code?

---

<div class="post-metadata">

### Author: ![system](https://canada1.discourse-cdn.com/flex011/uploads/kirupa/original/3X/6/2/621e5c11736f46532526e61be85940af4230f3e5.png) [@system](https://forum.kirupa.com/u/system)
#### Post date: [June 17, 2004, 5:28am UTC](https://forum.kirupa.com/t/button-start-mc/113361/3 "2004-06-17T05:28:50Z")

</div>

eze, your for loop isnt proper syntax…  
[AS]  
for (var i = 0, i \< button\_array.length, i++) {  
//statements;  
}  
[/AS]

---

<div class="post-metadata">

### Author: ![system](https://canada1.discourse-cdn.com/flex011/uploads/kirupa/original/3X/6/2/621e5c11736f46532526e61be85940af4230f3e5.png) [@system](https://forum.kirupa.com/u/system)
#### Post date: [June 17, 2004, 5:39am UTC](https://forum.kirupa.com/t/button-start-mc/113361/4 "2004-06-17T05:39:12Z")

</div>

yea it is, dunno what its called but that isnt the problem, BTW lostinbeta gave me the first code, well modded mine to that so it is working and it works for the gotoAndPlay part of the function, just not the \_root.fromName varible doesnt seem to be set

---

<div class="post-metadata">

### Author: ![system](https://canada1.discourse-cdn.com/flex011/uploads/kirupa/original/3X/6/2/621e5c11736f46532526e61be85940af4230f3e5.png) [@system](https://forum.kirupa.com/u/system)
#### Post date: [June 17, 2004, 9:39am UTC](https://forum.kirupa.com/t/button-start-mc/113361/5 "2004-06-17T09:39:31Z")

</div>

```auto
button_array = ["home", "plans", "terms", "contact"];
for (var i in button_array) {
 btn = this[button_array*];
 btn.clip = this[button_array*]+"_mc";
 btn.onRelease = function() {
  _root.fromName = this.clip;
  content_mc.gotoAndPlay(36);
 };
}

```

??

scotty(-:

---

<div class="post-metadata">

### Author: ![system](https://canada1.discourse-cdn.com/flex011/uploads/kirupa/original/3X/6/2/621e5c11736f46532526e61be85940af4230f3e5.png) [@system](https://forum.kirupa.com/u/system)
#### Post date: [June 17, 2004, 10:32am UTC](https://forum.kirupa.com/t/button-start-mc/113361/6 "2004-06-17T10:32:13Z")

</div>

whats the var “clip” in btn? and whats btn?

btn should be defined f.e. as a MovieClip (like in btn = new MovieClip()😉 if you want to attach the var clip to it.  
Its not like you can grab a varname out of the blue and put another var in it.  
Ive experienced the same problem time after time, till i discovered in a case like this that the var clip doesnt really exist at all.

so my solution to your code is this (and this one does work!) :  
(make sure you have a movieClip on your stage called “btn\_mc” with a button in it called “btn”)

```auto

button_array = new Array("home", "plans", "terms", "contact");
singleButton = new Array();
for (var i in button_array) {
singleButton* = btn;
singleButton*.btn.clip = button_array*;
singleButton*.btn.clipname = button_array*+"_mc";
//trace(singleButton*.clip);
singleButton*.btn.onRelease = function() {
//_root.fromName = this.clip;
trace(this.clip);
trace(this.clipname);
//content_mc.gotoAndPlay(36);
};
}

```

enjoy, gl =]

---

<div class="post-metadata">

### Author: ![system](https://canada1.discourse-cdn.com/flex011/uploads/kirupa/original/3X/6/2/621e5c11736f46532526e61be85940af4230f3e5.png) [@system](https://forum.kirupa.com/u/system)
#### Post date: [June 17, 2004, 11:10am UTC](https://forum.kirupa.com/t/button-start-mc/113361/7 "2004-06-17T11:10:14Z")

</div>

My bad, try

```auto
        
button_array = ["home", "plans", "terms", "contact"];
for (var i in button_array) {
 btn = this[button_array*];
 btn.i = i;
 btn.onRelease = function() {
  _root.fromName = button_array[this.i]+"_mc";
  content_mc.gotoAndPlay(36);
 };
}

```

scotty(-:

---

<div class="post-metadata">

### Author: ![system](https://canada1.discourse-cdn.com/flex011/uploads/kirupa/original/3X/6/2/621e5c11736f46532526e61be85940af4230f3e5.png) [@system](https://forum.kirupa.com/u/system)
#### Post date: [June 17, 2004, 11:13am UTC](https://forum.kirupa.com/t/button-start-mc/113361/8 "2004-06-17T11:13:33Z")

</div>

thanks scotty works like a charm 😃

If you got time would you mind explaining why you changed it like you did 😃 thanks again,  
Josh.
