Thanks Sean. I noticed it too. Since I am a novice I suspected I was making an error somewhere. So I decided to take a second opinion :)
Now I seem to have identified the bug. The corrected lib can be found here. http://gist.github.com/raw/589185/09ca0dea770aff745ab9f429920f132dba0230c3/mcl-min.js Thanks for your assistance. On Sep 20, 9:49 pm, Sean McArthur <[email protected]> wrote: > I've never used it, and I haven't had time to read the source code, but the > documentation suggests that you pass the item ID to `remove`. > > CANVAS.layers.get('myLayer').remove(foo.id); > > Yet, that didn't work either... So I searched the source code. It seems the > Layer.remove function has a bug in it. It doesn't pass the ID to the destroy > and erase methods, it passes the hard coded string 'id'. > > > > On Mon, Sep 20, 2010 at 2:08 AM, shouvik <[email protected]> wrote: > > Hi All, > > > I have asked this question before and it seemed that the code I was > > using was pretty confusing. So this is a virtually dumbed down version > > of the same code. I draw a square on the canvas using the add > > function. Likewise I should be able to remove the item from the canvas > > using the remove function! Alas, it doesn't seem to happen. > > > Here is the code > > > $(window).addEvent('load',function(){ > > > CANVAS.init({ canvasElement : 'canvas' }); > > CANVAS.layers.add( new Layer({ > > id : 'myLayer' > > })); > > > var colors = [ > > 'rgba(255,0,0,1)', > > ]; > > > 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; > > ctx.fillRect(this.x,this.y,200,200); > > } > > } > > }); > > > CANVAS.layers.get('myLayer').add(foo); > > CANVAS.draw(); > > CANVAS.layers.get('myLayer').remove(foo); > > CANVAS.draw(); > > }); > > > It can also be seen here is jsfiddle > >http://jsfiddle.net/WRRns/4/ > > The library I am using to implement this is via mootools canvas > > library. Here is the link of the functions. > >http://forvar.de/js/mcl/docs.Layer.html#fn-remove > > > Thanks
