I am able to draw the box but I am not able to remove it! (Canvas)

I have asked this question before and it seemed that the code I was using was pretty confusing. So this is a virtually dumed down version of the same code. I draw a square on the canvas using the add function. Like wise I should be able to remove the item from the canvas using the remove function! Alas it doesn't seem to happen so.

Here is the code


CANVAS.init({ canvasElement : 'canvas' });
CANVAS.layers.add( new Layer({
    id : 'myLayer'

var colors = [

var pos = [
    { x: 150, y : 100 },

       var foo = new CanvasItem({
        id : 'item',
        x : pos[0].x,
        y : pos[0].y,
        fillStyle : colors[0],
        events : {
            onDraw : function(ctx)
                ctx.fillStyle = this.fillStyle;


It can also be seen here is jsfiddle

The library I am using to implement this is via mootools canvas library. Here is the link of the functions.

Hopefully this will help people get my query. Feel free to ask questions if you are still pondering about what exactly is my problem! Thanks

EDIT : There is a bug in the library. Please find the link to the corrected code below in the comments of the answer. Thanks.



Looking at the docs of the remove function it seems that you should be passing the itemId not the the actual item object when calling it.


the error in the library was in the remove function. I have the following script which removes the bug. Hope it helps people. :)



Recent Questions

Top Questions

Home Tags Terms of Service Privacy Policy DMCA Contact Us

©2020 All rights reserved.