![]() |
| ||
| Getting funky errors with a simple for loop, anyone care to help? Hello All, I have a javascript image preloading script I'm writing, and it basically creates an array called "array_name" which contains the image filenames, and then uses a for loop to assign "array_name"'s elements to another array called "preload". I know my syntax is good, but the firefox javascript inspector is complaining each time I attempt to run this. Can anyone take a look at the code, and tell me what I'm doing wrong? Thank You function imgLoad() { |
| ||
| Re: Getting funky errors with a simple for loop, anyone care to help? try replacing: array_name=[];with: array_name= new Array(); What is the error produced? |
| ||
| Re: Getting funky errors with a simple for loop, anyone care to help? Quote:
The error thats produced is: missing ; before statement var preload[i] = new Image(); imgarray.js (line 31) Though honestly, I think I'm going to ignore this error. I just noticed that the firefox javascript inspector reports no errors with it, however "Firebug" (an extension I have installed) found error with it. If you see something I'm doing wrong, or something that's bad style which would cause Firebug to spit out errors, feel free to let me know, otherwise I'm gonna consider this problem "solved". |
| ||
| Re: Getting funky errors with a simple for loop, anyone care to help? ha... the only thing i can think is: for (var i = 0; i < array_name.length; i++;) {but hey, i've never seen that last ; put in, and it shouldn't (doesn't need to) be put in really... EDIT: Actually, this seems wrong/uneccessary: var preload[i] = new Image();
preload[i] is already indirectly "var'd" when you make the array. |
| ||
| Re: Getting funky errors with a simple for loop, anyone care to help? Yea, I actually didn't have ; there before, just put it there to see if it would "fix" the problem. I thought that I had to put var in front of all variables that appear within a for loop, so that they stay local? Anyways, thanks for the help. |
| ||
| Re: Getting funky errors with a simple for loop, anyone care to help? thats not a local variable; you are assigning index "i", of the inherited scope/routine scope/public scope array "preload" to reference a new Image object, which is automatically var'd and scoped by that assignment (infact, you'll find that Image isn't accessible by any scope; its scope sort of disapears, and it can only be accessed through the array) If you were doing this: for (var i = 0; i < array_name.length; i++) {
then you'd need (or should use) the var. |
| All times are GMT -4. The time now is 10:25 pm. |
Forum system based on vBulletin Copyright ©2000 - 2008, Jelsoft Enterprises Ltd.
©2003 - 2008 DaniWeb® LLC