I really appreciate all the hints.
However:
Code:
var loadPictureOnCanvas = function (index, url, sourcepointer, widthpic, heightcanvas) {
img[index] = new Image();
img[index].onload = function() {
contextsrc.drawImage(img[index], sourcepointer, 0, widthpic, heightcanvas);
};
img[index].src = url;
alert(index);
}
var copyCanvas = function(callback) {
contextdest.drawImage(canvassrc, 0, 0, widthcanvas, heightcanvas, 0, 0, widthcanvas, heightcanvas);
alert('thenCopy');
return callback;
}
var makeSourceCanvas = function(callback) {
for (i=0; i<numberofpics; i++) {
loadPictureOnCanvas(i, imgsrc[i], sourcepointer, widthpic[i], heightcanvas);
sourcepointer=sourcepointer+widthpic[i];
}
alert('makeSource');
return callback;
}
copyCanvas(makeSourceCanvas(callback));
...gives exactly the same issue.
Now I have never worked with asynchronous code before, so I may be entirely missing the purpose of callbacks... Apparently I do, else this would have worked.