tengo el siguienete script:
Código Javascript:
Ver original
Animation=function(spr,spd) { this.initialize({ sprite:spr, speed:spd, frames:[], timer:null, count:0 }); } Animation.prototype={ addFrame: function (id) { spr=this this.frames[frames.length]={ id:id, sprite:"url('"+spr.sprite.image.src+"') "+spr.sprite.frames[id].x+"px "+spr.sprite.frames[id].y+"px;" } }, drawAnimation:function (con, id) { alert(con) image=document.createElement('img') image.setAttribute('src','sprites/empy.gif') image.setAttribute('style',"background:"+this.frames[0].sprite) image.setAttribute('class','animation') image.setAttribute('width',this.sprite.width) image.setAttribute('height',this.sprite.height) image.setAttribute('id',id) con.appendChild(image) this.id=document.getElementById(id) this.timer=setInterval(this.play,this.speed); }, play:function() { if (this.count=this.frames.length) { this.count=0 } else { this.count++ } this.id.style.background=this.frames[this.count] } } avatar=new Sprite('sprites/avatars/ash_walking.gif',28,38,0,0,0,2,3,4); aniAvatar=new Animation(avatar,50); aniAvatar.addFrame(0); aniAvatar.addFrame(1); aniAvatar.addFrame(0); aniAvatar.addFrame(2); window.onload=function() {aniAvatar.drawAnimation($('con'),'IMGavatar')}
mi problema esque cunado se ejecuta la funcion play(), me aparce como error: this.id is undefined.
en realidad esque no tengo mucha experiencia con DOM y no se como referirme a un objeto creado con DOM.