0

I have my canvas saved as an object but it won't let me add an eventListener because it creates this error:

Object #<Object> has no method 'addEventListener' 

This is how i create the canvas:

    var i = 1;
    document.getElementById("G").innerHTML += '<canvas id="layer'+i+'" class="c" style="z-index:'+i+';"></canvas>'; 
    temp = document.getElementById('layer'+i);
    objname = 'canvas'+i;
    canvas[objname] = new Object();
    canvas[objname].ctx =  temp.getContext("2d");   

Then i do:

canvas.canvas1.addEventListener("mousedown", fnc_test, false);

Any ideas why this is not allowed, or where I am going wrong??


I think you meant

canvas[objname] = temp;
canvas[objname].ctx = temp.getContent("2d");

There is absolutely no reasoning for the new Object there...

4

1 回答 1

1

I think you meant

canvas[objname] = temp;
canvas[objname].ctx = temp.getContent("2d");

There is absolutely no reasoning for the new Object there...

于 2012-12-06T06:00:04.263 回答