So, I'm using whatever Object-Oriented options has to try and make a neat static image class so all I have to do is add said class to Canvas, and it will draw itself out! To test if everything worked, I added up some alerts. Now my Function starts spewing 'undefined' at the third alert.
function StaticImage(imgsource, cancontext, ex, wy) {
this.x = ex;
this.y = wy;
this.context = cancontext;
alert("Image class instantiated! " + imgsource);
this.draw = function () {
this.image = new Image();
this.image.src = imgsource;
alert("Draw function called!");
this.image.onload = function () {
alert(this.image + " loaded! drawing on: " + this.context + " at: " + this.x + ":" + this.py);
};
this.cancontext.drawImage(this.image, this.x, this.y);
}
}
so, that would be the class, and this is the bit of Javascript used on the HTML Page that keeps the Canvas. First it creates the image bla.jpg, and then it does the same, only with the class...
var canvas = document.getElementById("canvas");
var context = canvas.getContext("2d");
var bla = new Image();
bla.src = "bla.jpg";
bla.onload = function () {
context.drawImage(bla, 50, 50);
};
var lol = new StaticImage("bla.jpg", context, 200, 200);
lol.draw();