M
Matthew Crouch
okay, i've got a server-side (php) script creating a bunch of JS image
vars in a loop ..
{{foreach from=$button_names_array key=key item=button_name}}
var {{$button_name}}_up = new Image();
{{$button_name}}_up.src =
"{{$LAYOUT_IMAGE_DIR}}/gnav/{{$button_name}}_off.gif" ;
var {{$button_name}}_down = new Image() ;
{{$button_name}}_down.src =
"{{$LAYOUT_IMAGE_DIR}}/gnav/{{$button_name}}_on.gif" ;
(those are smarty tags -- it's not important)
the doPreload() I inherited .. have no idea where it came from
function doPreload(imgObj,imgSrc) {
if (document.images) {
eval(imgObj + ' = new Image()');
eval(imgObj + '.src = "' + imgSrc + '"');
}
}
But I (finally) have a javascript console going, and it warns
"assignment to undeclared variable gnav_ho (the name of the image) ... "
Then, obviously, similar warning for each one in the loop.
For kicks i changed to
eval(var imgObj + ' = new Image()');
which made the warning go away, but the image doesn't show up. I
personally don't care -- I'll use the working/warning version ... just
thought this might be a good potential learning experience, as
undecalred vars are giving me trouble routinely....
Thanks to all, you're slowly convincing me that this language is worth
learning.
vars in a loop ..
{{foreach from=$button_names_array key=key item=button_name}}
var {{$button_name}}_up = new Image();
{{$button_name}}_up.src =
"{{$LAYOUT_IMAGE_DIR}}/gnav/{{$button_name}}_off.gif" ;
var {{$button_name}}_down = new Image() ;
{{$button_name}}_down.src =
"{{$LAYOUT_IMAGE_DIR}}/gnav/{{$button_name}}_on.gif" ;
(those are smarty tags -- it's not important)
the doPreload() I inherited .. have no idea where it came from
function doPreload(imgObj,imgSrc) {
if (document.images) {
eval(imgObj + ' = new Image()');
eval(imgObj + '.src = "' + imgSrc + '"');
}
}
But I (finally) have a javascript console going, and it warns
"assignment to undeclared variable gnav_ho (the name of the image) ... "
Then, obviously, similar warning for each one in the loop.
For kicks i changed to
eval(var imgObj + ' = new Image()');
which made the warning go away, but the image doesn't show up. I
personally don't care -- I'll use the working/warning version ... just
thought this might be a good potential learning experience, as
undecalred vars are giving me trouble routinely....
Thanks to all, you're slowly convincing me that this language is worth
learning.