I’m trying to do a setTimeout where I pass variables to the function being called within the setTimeout(). After some initial failures and then using The Google I found a site that described how to do it using closures. I pretty much followed the example but I keep getting an error message:
missing ) after argument list
This error message is being called on the setTimeout but as far as I can tell everything is closed off. Any help would be appreciated:
var textureAtlas = new Image()
function init() {
textureAtlas.src = "images/textureatlast1.png";
var textureAtlasCoords = new Array("0,0", "100,0", "200,0", "300,0", "400,0", "500,0", "600,0");
var canvas = document.getElementById('textureAtlas');
if (canvas.getContext){
var ctx = canvas.getContext('2d');
for(var c=0; c<textureAtlasCoords.length; c++) {
var thisCoord = textureAtlasCoords[c];
var thisCoordSplit = thisCoord.split(",");
var thisX = thisCoordSplit[0];
var thisY = thisCoordSplit[1];
var a = setTimeout(animate(){myFunction(ctx, textureAtlas, thisX, thisY); ctx=null, textureAtlas=null, thisX=null, thisY=null},1000);
}
} else {
alert("Looks like your browser doesn't support HTML5");
}
}
function animate() {
ctx.drawImage(thisImg,thisX,thisY, 1024, 451, 0, 0, 1024, 451);
}
Also:
The context here will throw ‘undefined’, as the
will only be available within the scope of init.
You don’t strictly need a ‘;’ after the first line:
However, it would be a very good idea, see: does javascript require ';' at the end of a line of code?