Tek-Tips is the largest IT community on the Internet today!

Members share and learn making Tek-Tips Forums the best source of peer-reviewed technical information on the Internet!

  • Congratulations Chris Miller on being selected by the Tek-Tips community for having the most helpful posts in the forums last week. Way to Go!

Can you assign functions as part of a loop?

Status
Not open for further replies.

fedtrain

Instructor
Jun 23, 2004
142
US
I am not sure even how to search on this one so after a fruitless effort I'll just post it...

I have an array of items. I want to run through the array using 'for (i=0, i < array.length, i++)' . Now on each time I want to say something like...

Code:
this["bt"+toolsArray[i]].onRollOver = function(){
if ("bt"+toolsArray[i]._x == 13){
	this["bt"+toolsArray[i]].toolTab._visible = true;
	this["bt"+toolsArray[i]]._alpha = 50;
	}
}
this["bt"+toolsArray[i]].onRollOut = function (){
if (this["bt"+toolsArray[i]]._x ==13) {
	this["bt"+toolsArray[i]].toolTab._visible = false;
	}
}

But I am not getting any results at all. I am attempting to build a product that produces all my buttons and actions with some generic code instead of writting a button for each item in the array. The intention is to make this tool easier for others to update in the future.

Dave

"Credit belongs to the man who is actually in the arena - T.Roosevelt
 
Never mind....duh.

Ok...I was making the wrong reference. It seems you have to do it like this...

Code:
this["bt"+toolsArray[i]].onRollOver = function(){
if (this._x == 13){
    this.toolTab._visible = true;
    this._alpha = 50;
    }
}

Well maybe my public humiliation will help someone else someday.

<sigh>

"Credit belongs to the man who is actually in the arena - T.Roosevelt
 
Fed, dont worry about it, i was working on something similar a while back and couldnt figure it out.

FYI, each name must be in [] so if you are doing something like (and this is a big like, i did it once 3 months ago)

toys.redCat4.bgColor="red"
toys[strColor+strAnimal+intNum]bgColor="red"

Without Tek-Tips I would go Codal
-implementing random bugs for the sake of something to do.
 
Status
Not open for further replies.

Part and Inventory Search

Sponsor

Back
Top