I'm stumling upon a weird problem: The code just wont be able to access the canvas element. Consider this code:
this.canvas = document.getElementById('canvas');
this.context2D = this.canvas.getContext('2d');
Firefox would produce an error say this.canvas is null
. But if I write it like this:
this.canvas = $('#canvas');
this.context2D = this.canvas.getContext('2d');
Firefox would tell getContext is not a method
. I looked into this.canvas
and see an unfamiliar object (no idea where it comes from but it definitely not a canvas).
And this is not exclusive to Firefox, Chrome produce the same result. I'm getting crazy over this.
edit: the entire html is here
<!DOCTYPE HTML>
<html lang="en">
<head>
<title>Background test</title>
<script type="text/javascript" src="Scripts/jquery-1.4.2.min.js"></script>
<script type="text/javascript" src="Scripts/soundmanager2.js"></script>
<script type="text/javascript" src="Scripts/base.js"></script>
<script type="text/javascript" src="Scripts/Resources.js"></script>
<script type="text/javascript" src="Scripts/Actor.js"></script>
<script type="text/javascript" src="Scripts/Commons.js"></script>
<script type="text/javascript" src="Scripts/Graphics.js"></script>
<script type="text/javascript" src="Scripts/Utils.js"></script>
<script type="text/javascript">
window.onload = function(){
new Commons().startupCommons();
new Graphics().startupGraphics();
}
</script>
<style type="text/css">
body { font-family: Arial,Helvetica,sans-serif;}
canvas {border-style:solid; border-width:5px; border-color:green;}
</style>
</head>
<body>
<canvas id="visualcanvas" width="800" height="600">
<p>
Your browser does not support the canvas element.
</p>
</canvas>
</body>
</html>
I just added window.onload, but the problem persist. this
in the before code refer to the Graphics object, which is call when window.onload
fire.