This is my code, the issue is in the ldimg(); and the img(); ldimg(); creates the image element, and img(); gets it, but my alert() debugging test says cannot read source of null.
function ldimg(src, name) {
var imageObj = document.createElement('img');
imageObj.onload = function() {
context.drawImage(imageObj, window.innerWidth + 100, window.innerHeight + 1, 1, 1);
};
imageObj.src = src;
imageObj.id = name;
}
function img(name, x, y, width, height) {
var image = document.getElementById(name);
alert(image.src);
}
ldimg('bot.png', 'bot');
function Loop() {
setTimeout(function() {
img('bot', 100, 100, 100, 100);
Loop();
}, 16);
}
Loop();
</script>
</html>
You could restructure the code to return the image from ldimg if you aren't intending to add it to the DOM.