JS: Why isn't this variable available to the other functions?
Posted
by
Marius Jonsson
on Stack Overflow
See other posts from Stack Overflow
or by Marius Jonsson
Published on 2010-12-27T01:27:45Z
Indexed on
2010/12/27
1:54 UTC
Read the original article
Hit count: 271
Hello there,
I've am trying to make a canvas animation:
var context;
var meter;
var pin;
function init() {
var meter = new Image();
var pin = new Image();
var context = document.getElementById('canvas').getContext('2d');
meter.src = 'background.png';
pin.src = 'needle.png';
context.drawImage(meter,0,0);
context.translate(275,297);
context.save();
setTimeout(startup,500);
}
function startup() {
var r=2; // set rpm here.
var i=r*36-27;
var angleInRadians = 3.14159265 * i/180; //converting degree to radian
context.rotate(angleInRadians); //rotating by angle
context.drawImage(pin,-250,-3); //adjusting pin center at meter center
context.restore();
}
You can see the script at http://www.kingoslo.com/instruments/
With firebug I get error saying that context is undefined, which I think is strange.
Thanks.
Kind regards, Marius
© Stack Overflow or respective owner