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 IamaSherpa on being selected by the Tek-Tips community for having the most helpful posts in the forums last week. Way to Go!

image preload script 1

Status
Not open for further replies.

gollyg

Technical User
Oct 24, 2000
131
AU
Hi,

I've been trying to write something to simplify the preloading for my buttons. There are two button states and they are named button.gif and button_o.gif (where button is a unique name for the button). So the code needs to introduce button as a new image and set the source property. But it doesn't! Any help much appreciated.
Code:
navImgs = 
["commit","contact","dates","draw","entry","finals","links","results",
"rules","scores","teams","winners"]


	buttons = new Array()
	buttons_o = new Array()

for (i in navImgs)
	{

		buttons[i] = new Image
		buttons_o[i] = new Image		
		
		
		buttons[i].src  = "images/" + navImgs[i] + ".gif"
		buttons[i].name  = navImgs[i]
		buttons_o[i].src  = "images/" + navImgs[i] + "_o.gif"
		buttons_o[i].name  = navImgs[i] + "_o"

	}
 
A good friend of mine FlatHead asked the same question on the HTML forum a few weeks ago, check out what responses he got.

thread215-35432 DeltaFlyer ;-)

DeltaFlyer - The Only Programmer To Crash With Style.
 
I'm not sure but I think you need to define the array elements before you can assign an object to them, had a similar problem a few weeks ago.
Try declaring the arrays:
var buttons = new Array [navImgs.length]
ver buttons_o = new Array [navImgs.length]
Hope that helps.
R.
 
Thanks alot for your replies. It's great that people actually want to help out! I think I found the problem - I forgot the () after declaring the new image objects. Seems to be working now.

Thanks again

j
 
Thanks mackjack, nice simple site that tells you exactly what you need.
 
Status
Not open for further replies.

Part and Inventory Search

Sponsor

Back
Top