Ver Mensaje Individual
  #1 (permalink)  
Antiguo 30/01/2010, 23:12
Avatar de ClubIce
ClubIce
 
Fecha de Ingreso: diciembre-2008
Mensajes: 216
Antigüedad: 16 años, 1 mes
Puntos: 2
Pregunta [R] no detecta ID

Hola,

tengo el siguienete script:

Código Javascript:
Ver original
  1. Animation=function(spr,spd) {
  2.  this.initialize({
  3.   sprite:spr,
  4.   speed:spd,
  5.   frames:[],
  6.   timer:null,
  7.   count:0
  8.  });
  9. }
  10. Animation.prototype={
  11.  addFrame: function (id) {
  12.   spr=this
  13.   this.frames[frames.length]={
  14.    id:id,
  15.    sprite:"url('"+spr.sprite.image.src+"') "+spr.sprite.frames[id].x+"px "+spr.sprite.frames[id].y+"px;"
  16.   }
  17.  },
  18.  drawAnimation:function (con, id) {
  19.   alert(con)
  20.   image=document.createElement('img')
  21.   image.setAttribute('src','sprites/empy.gif')
  22.   image.setAttribute('style',"background:"+this.frames[0].sprite)
  23.   image.setAttribute('class','animation')
  24.   image.setAttribute('width',this.sprite.width)
  25.   image.setAttribute('height',this.sprite.height)
  26.   image.setAttribute('id',id)
  27.   con.appendChild(image)
  28.   this.id=document.getElementById(id)
  29.   this.timer=setInterval(this.play,this.speed);
  30.  },
  31.  play:function() {
  32.   if (this.count=this.frames.length) {
  33.    this.count=0
  34.   } else {
  35.    this.count++
  36.   }
  37.   this.id.style.background=this.frames[this.count]
  38.  }
  39. }
  40. avatar=new Sprite('sprites/avatars/ash_walking.gif',28,38,0,0,0,2,3,4);
  41. aniAvatar=new Animation(avatar,50);
  42. aniAvatar.addFrame(0);
  43. aniAvatar.addFrame(1);
  44. aniAvatar.addFrame(0);
  45. aniAvatar.addFrame(2);
  46. 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.

Última edición por ClubIce; 01/02/2010 a las 00:36