# \[FMX\]Integrate loop in function?

**URL:** https://forum.kirupa.com/t/fmx-integrate-loop-in-function/59966
**Category:** Uncategorized
**Created:** [August 5, 2004, 5:25am UTC](https://forum.kirupa.com/t/fmx-integrate-loop-in-function/59966 "2004-08-05T05:25:14Z")
**Posts on this page:** 12
**Page:** 1

<div class="post-metadata">

### Author: ![dboers](https://avatars.discourse-cdn.com/v4/letter/d/bbe5ce/32.png) [@dboers](https://forum.kirupa.com/u/dboers)
#### Post date: [August 5, 2004, 5:25am UTC](https://forum.kirupa.com/t/fmx-integrate-loop-in-function/59966/1 "2004-08-05T05:25:14Z")

</div>

I made a [color=red]for in[/color] loop and a [color=red]function[/color] to control my button mc’s like this:

```auto
for (var i in this) {
 if (this*._name.substr(0, 4) == "btn_") {
  setButton(this*._name);
 }
}
function setButton(clip) {
 var clip = eval(clip);
// The rollOver, rollOut and release stuff goes here
}

```

Now I would like to integrate the loop in the function ! I tried the following:

```auto
function setButton(clip) {
 for (var i in this) {
  if (this*._name.substr(0, 4) == "btn_") {
   var clip = eval(this*._name);
// clip.onRollover = function(){ and the rollOut and release stuff goes here
}
}
} 
} 

```

but that isn’t working. Can somebody please tell me what I’m doing wrong.

Thanks in advance

---

<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: [August 5, 2004, 7:32am UTC](https://forum.kirupa.com/t/fmx-integrate-loop-in-function/59966/2 "2004-08-05T07:32:25Z")

</div>

I now added: [color=red]substr(4)[/color]

to the var clip part, so the complete syntax is now:

[color=red]var clip = eval(this\*.\_name.substr(4));[/color]

but still nothing. Anybody an idea what is wrong or else any sugestions where I probably can find the answer

Thanks in advance

---

<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: [August 5, 2004, 11:06am UTC](https://forum.kirupa.com/t/fmx-integrate-loop-in-function/59966/3 "2004-08-05T11:06:44Z")

</div>

the eval is pointless… you have a direct clip reference from your for in loop

this[i] IS the clip. Theres no point in getting the clips name from THE clip and then converting it _back_ to the clip again 😉

is the function defined in the same timeline where those buttons exist? If so (which is right) I just suggest trying some traces in there to make sure you’re actually finding your buttons in the loop i.e. trace(this\*)

---

<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: [August 5, 2004, 11:27am UTC](https://forum.kirupa.com/t/fmx-integrate-loop-in-function/59966/4 "2004-08-05T11:27:55Z")

</div>

It is realy strange. The trace give no result. They are on the same timeline indeed. And if I place the for in loop outsite the function they are working fine. I realy don’t understand what i’m doing wrong ?

---

<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: [August 9, 2004, 7:38am UTC](https://forum.kirupa.com/t/fmx-integrate-loop-in-function/59966/5 "2004-08-09T07:38:55Z")

</div>

I still haven’t figured out why the “btn\_” mc’s are not working any more after I integrated the for in loop in the function. This is how I have it now:

```auto
function setButton(clip) {
for (var i in this) {
if (this*._name.substr(0, 4) == "btn_") {
var clip = this*;
// clip.onRollover = function(){ and the rollOut and release stuff goes here
}
}
} 
}

```

The function is on the main timeline but I the btn\_ mc’s I have to control are insite another MC “menuMC”

Can somebody please help me :crying:

---

<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: [August 9, 2004, 9:24am UTC](https://forum.kirupa.com/t/fmx-integrate-loop-in-function/59966/6 "2004-08-09T09:24:21Z")

</div>

> [@dboers](#):
>
> I still haven’t figured out why the “btn\_” mc’s are not working any more after I integrated the for in loop in the function. This is how I have it now:
> 
> ```auto
> function setButton(clip) {
> for (var i in this) {
> if (this*._name.substr(0, 4) == "btn_") {
> var clip = this*;
> // clip.onRollover = function(){ and the rollOut and release stuff goes here
> }
> }
> } 
> }
> 
> ```
> 
> The function is on the main timeline but I the btn\_ mc’s I have to control are insite another MC “menuMC”
> 
> Can somebody please help me :crying:

function setButton() {  
for (var i in menuMc) {  
if (menuMc\*._name.substr(0, 4) == "btn_") {  
clip = menuMc\*;  
clip.onRollOver = function() {  
trace(this.\_name);  
};  
}  
}  
}  
setButton();

---

<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: [August 9, 2004, 9:56am UTC](https://forum.kirupa.com/t/fmx-integrate-loop-in-function/59966/7 "2004-08-09T09:56:34Z")

</div>

Thank you very much stringy :hugegrin: This is great :thumb:

---

<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: [August 9, 2004, 10:10am UTC](https://forum.kirupa.com/t/fmx-integrate-loop-in-function/59966/8 "2004-08-09T10:10:19Z")

</div>

> [@dboers](#):
>
> Thank you very much stringy :hugegrin: This is great :thumb:

welcome  
Glad it worked but the other poster asked if your buttons were in the sametimeline as the 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: [August 9, 2004, 10:23am UTC](https://forum.kirupa.com/t/fmx-integrate-loop-in-function/59966/9 "2004-08-09T10:23:03Z")

</div>

I know, but at that time they where. Only I changed a few things and that is why they are now integrated in that one MC. I have one more question if you don’t mind. This is my complete code:

```auto
_root.currMovie = "homede";
container.loadMovie(_root.currMovie+".swf");
function setButton() {
for (var i in menuMc) {
if (menuMc*._name.substr(0, 4) == "btn_") {
clip = menuMc*;
clip.onRollOver = function() {
	new Color(clip).setRGB(0xFFFFFF);
	trace(this._name);
};
clip.onRollOut = function() {
	if (!this.pushed) {
	 new Color(clip).setRGB(0x999999);
	} else {
	 new Color(clip).setRGB(0xFFFFFF);
	}
};
clip.onRelease = function() {
	resetKnop();
	this.pushed = true;
	new Color(clip).setRGB(0xFFFFFF);
	if (_root.currMovie == undefined) {
	 _root.currMovie = this._name.substring(4);
	 this._parent.container.loadMovie(this._name.substring(4)+".swf");
	} else if (_root.currMovie != this._name.substring(4)) {
	 if (this._parent.container._currentframe>=this._parent.container.midframe) {
	 _root.currMovie = this._name.substring(4);
	 this._parent.container.play();
	 }
	}
};
}
}
}
function resetKnop() {
for (var i in menuMC) {
if (menuMc*._name.substr(0, 4) == "btn_") {
clip = menuMc*;
clip.pushed = false;
new Color(clip).setRGB(0x999999);
}
}
}
setButton();

```

As you can see should the buttons change color on rollOver, rollOut and release. But that isn’t working. Nomather over which button I roll only the second one change color. What should I change to make this work again?

Thanks in advance

---

<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: [August 9, 2004, 10:27am UTC](https://forum.kirupa.com/t/fmx-integrate-loop-in-function/59966/10 "2004-08-09T10:27:21Z")

</div>

Problem solved 🙂 I changed new Color(clip) in new Color(this)

But what should I change to make this part work again:

```auto
	if (_root.currMovie == undefined) {
	 _root.currMovie = this._name.substring(4);
	 this._parent.container.loadMovie(this._name.substr ing(4)+".swf");
	} else if (_root.currMovie != this._name.substring(4)) {
	 if (this._parent.container._currentframe>=this._parent.container.midframe) {
	 _root.currMovie = this._name.substring(4);
	 this._parent.container.play();  

```

---

<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: [August 9, 2004, 5:40pm UTC](https://forum.kirupa.com/t/fmx-integrate-loop-in-function/59966/11 "2004-08-09T17:40:48Z")

</div>

> [@dboers](#):
>
> Problem solved 🙂 I changed new Color(clip) in new Color(this)
> 
> But what should I change to make this part work again:
> 
> ```auto
> if (_root.currMovie == undefined) {
> _root.currMovie = this._name.substring(4);
> this._parent.container.loadMovie(this._name.substr ing(4)+".swf");
> } else if (_root.currMovie != this._name.substring(4)) {
> if (this._parent.container._currentframe>=this._parent.container.midframe) {
> _root.currMovie = this._name.substring(4);
> this._parent.container.play();  
> 
> ```

Difficult to know without seeing the file. Is container on the main timeline?If so it should be this.\_parent.\_parent.container

---

<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: [August 10, 2004, 5:41am UTC](https://forum.kirupa.com/t/fmx-integrate-loop-in-function/59966/12 "2004-08-10T05:41:26Z")

</div>

That was indeed the solution 🙂 Thanks 🙂
