I made a [color=red]for in[/color] loop and a [color=red]function[/color] to control my button mc’s like this:
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:
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.
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*)
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 ?
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:
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”
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:
_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?