Foros del Web » Programando para Internet » Javascript »

no detecta ID

Estas en el tema de no detecta ID en el foro de Javascript en Foros del Web. Hola, tengo el siguienete script: @import url("http://static.forosdelweb.com/clientscript/vbulletin_css/geshi.css"); Código Javascript : Ver original Animation = function ( spr , spd ) {   this . initialize ...
  #1 (permalink)  
Antiguo 30/01/2010, 23:12
Avatar de ClubIce  
Fecha de Ingreso: diciembre-2008
Mensajes: 216
Antigüedad: 15 años, 4 meses
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
  #2 (permalink)  
Antiguo 30/01/2010, 23:35
Avatar de zerokilled
Javascripter
 
Fecha de Ingreso: abril-2009
Ubicación: Isla del Encanto, La Borinqueña [+>==]
Mensajes: 8.050
Antigüedad: 15 años
Puntos: 1485
Respuesta: no detecta ID

veamos! lo mas probable es que, tal como te lo indica el error, la propiedad id no esta definida en la instancia de Animation. el problema puede ser que estas invocando play antes de invocar drawAnimation. este ultimo es quien crea y agrega el elemento. de todos modos, dentro de play intenta hacer un alert de this.id para determinar que valor contiene en ese momento de invocacion.

por otro lado, a juzgar por el codigo, no comprendo porque crear el elemento y luego buscarlo por getElementById cuando puedes crear el elemento y hacerlo como una propiedad para las instancias Animation. de esta manera te evitas el paso de tener que buscar por dicho elemento. es decir, en tu funcion drawAnimation luego de crear la imagen asignas esta a la propiedad this.id. luego en play no tienes que buscarla, simplemente usas this.id.
__________________
la maldad es una virtud humana,
y la espiritualidad es la lucha del hombre contra su maldad.
  #3 (permalink)  
Antiguo 30/01/2010, 23:52
Avatar de ClubIce  
Fecha de Ingreso: diciembre-2008
Mensajes: 216
Antigüedad: 15 años, 4 meses
Puntos: 2
Respuesta: no detecta ID

no me funcion :(
  #4 (permalink)  
Antiguo 30/01/2010, 23:57
Avatar de zerokilled
Javascripter
 
Fecha de Ingreso: abril-2009
Ubicación: Isla del Encanto, La Borinqueña [+>==]
Mensajes: 8.050
Antigüedad: 15 años
Puntos: 1485
Respuesta: no detecta ID

¿como lo hicistes? lo que tenias que hacer era cambiar la linea #28 por this.id = image.
__________________
la maldad es una virtud humana,
y la espiritualidad es la lucha del hombre contra su maldad.
  #5 (permalink)  
Antiguo 31/01/2010, 00:04
Avatar de ClubIce  
Fecha de Ingreso: diciembre-2008
Mensajes: 216
Antigüedad: 15 años, 4 meses
Puntos: 2
Respuesta: no detecta ID

lo hize asi como dises, y hasta use alerts para comprovar que se eta pasando el valor, pero me sigue dando el mismo error
  #6 (permalink)  
Antiguo 31/01/2010, 00:30
Avatar de zerokilled
Javascripter
 
Fecha de Ingreso: abril-2009
Ubicación: Isla del Encanto, La Borinqueña [+>==]
Mensajes: 8.050
Antigüedad: 15 años
Puntos: 1485
Respuesta: no detecta ID

¿cabe la posiblidad que de que tengas un ejemplo en linea para comprobarlo? es que en mi interpretacion mental entiendo que debe funcionarte. ando un tanto vago como para preparar varias imagenes y escribir el resto del codigo que falta.

@edit,
no estoy seguro, sospecho que el problema esta en la linea #29. setInterval ejecuta la funcion en el contexto de window, de modo que la referencia this en play se refiere a window y no a la instancia creada. tienes que crear un closure de una variable que haga referencia a la instancia creada. probablemente como lo siguiente.
Código:
var that = this;
this.timer=setInterval(function(){that.play();},this.speed);
__________________
la maldad es una virtud humana,
y la espiritualidad es la lucha del hombre contra su maldad.

Última edición por zerokilled; 31/01/2010 a las 00:36
  #7 (permalink)  
Antiguo 31/01/2010, 00:39
Avatar de ClubIce  
Fecha de Ingreso: diciembre-2008
Mensajes: 216
Antigüedad: 15 años, 4 meses
Puntos: 2
Respuesta: no detecta ID

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.   id:null
  9.  });
  10. }
  11. Animation.prototype={
  12.  addFrame: function (id) {
  13.   spr=this
  14.   this.frames[frames.length]={
  15.    id:id,
  16.    sprite:"url('"+spr.sprite.image.src+"') "+spr.sprite.frames[id].x+"px "+spr.sprite.frames[id].y+"px;"
  17.   }
  18.  },
  19.  drawAnimation:function (con, id) {
  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.   this.id=image
  28.   con.appendChild(image)
  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. }
  #8 (permalink)  
Antiguo 31/01/2010, 00:52
Avatar de ClubIce  
Fecha de Ingreso: diciembre-2008
Mensajes: 216
Antigüedad: 15 años, 4 meses
Puntos: 2
Respuesta: no detecta ID

si era eso, ya me funciono, pero surge otro problema: la imagen no se mueve, JS no me cambia el Background: http://clubice.site50.net/eje/
  #9 (permalink)  
Antiguo 31/01/2010, 01:22
Avatar de zerokilled
Javascripter
 
Fecha de Ingreso: abril-2009
Ubicación: Isla del Encanto, La Borinqueña [+>==]
Mensajes: 8.050
Antigüedad: 15 años
Puntos: 1485
Respuesta: no detecta ID

el problema va por estos tiros, a ver si lo encuentras antes que yo. la consola de firefox me dice Warning: Expected end of value but found '['. Error in parsing value for 'background'. Declaration dropped. o sea, se esta asignando un valor invalido a la propiedad background. todavia no encuentro cual es. aparte, en la funcion play tienes un error al comprar el conteo, if (this.count=this.frames.length) fijate que deberias usar el operador == y no el de asignacion.
__________________
la maldad es una virtud humana,
y la espiritualidad es la lucha del hombre contra su maldad.
  #10 (permalink)  
Antiguo 31/01/2010, 02:29
Avatar de zerokilled
Javascripter
 
Fecha de Ingreso: abril-2009
Ubicación: Isla del Encanto, La Borinqueña [+>==]
Mensajes: 8.050
Antigüedad: 15 años
Puntos: 1485
Respuesta: no detecta ID

ya encontre el problema, pero no es el unico, todavia tienes mas. te los dejare para que vayas mejorando. el de este caso particular esta en la funcion play. fijate en la linea #37 le estas asignando un objeto a la propiedad background. por eso es que indica el error que antes te indique. al ser un objeto javascript lo intenta convertir a string porque es el tipo de dato que acepta las propiedades css. un objeto convertido a string resulta un valor invalido para las propiedades css, o sea luego de la conversion la propiedad adquiere el valor [object Object]. en este caso lo que quisistes asignar fue la propiedad sprite de dicho objeto. luego muestra el siguiente error: Warning: Expected end of value but found ';'. Error in parsing value for 'background'. Declaration dropped. este se debe porque estas incluyendo el punto y coma (;) en el string que sera asignado como valor a la propiedad background. aunque en css cada declaracion la terminamos con punto y coma en javascript no se incluye.
__________________
la maldad es una virtud humana,
y la espiritualidad es la lucha del hombre contra su maldad.
  #11 (permalink)  
Antiguo 31/01/2010, 13:23
Avatar de ClubIce  
Fecha de Ingreso: diciembre-2008
Mensajes: 216
Antigüedad: 15 años, 4 meses
Puntos: 2
Respuesta: no detecta ID

ya me funciona, pero yengo otro problema, ahora es con la funcion Sprite(), en el momento que asigna "x" y "y" no me los asigna como debe ser, a medida que va asignando me va pasando un incremiento demaciado grande!!!, en realidad nesesito lograr asignar "x" y "y" de forma que cada cuadro encaje correctamente usando los parametros que le paso a Sprite()
  #12 (permalink)  
Antiguo 31/01/2010, 17:31
Avatar de zerokilled
Javascripter
 
Fecha de Ingreso: abril-2009
Ubicación: Isla del Encanto, La Borinqueña [+>==]
Mensajes: 8.050
Antigüedad: 15 años
Puntos: 1485
Respuesta: no detecta ID

la verdad era un tanto confuso entender porque no alineaba bien, ya me habia fijado de eso. en todo caso son por dos razones. primero que hay marcos de la imagen sprite estan mal alineado o que contiene una dimension distinta a los parametros que indicas. supone que la dimension de cada marco es de 28x38 pero por ejemplo pero por ejemplo la segunda y tercera columna contiene dos pixeles mas en el ancho. me baso en estas indicaciones porque tuve que crear un nuevo sprite con una imagen propia. esta imagen simplemente consistia de bloques de colores, todos exactamente de las mismas dimensiones y separados por la misma cantidad de pixeles.

gracias a la nueva imagen surge la otra razon por la que no esta alineado. en la funcion Sprite estas calculando los parametros incorrectamente. el vspace debe calcularse junto con el ancho (width) y hspace con el height (alto). es decir, vspace se refiere al espacio entre columna de modo que se mide en horizontal. de la misma forma, hspace se refiere al espacio entre filas de modo que se mide en vertical. no lo he comprobado, pero lo mismo sucede con vmargin y hmarign: estan atado con el parametro incorrecto.
__________________
la maldad es una virtud humana,
y la espiritualidad es la lucha del hombre contra su maldad.
  #13 (permalink)  
Antiguo 31/01/2010, 17:38
Avatar de ClubIce  
Fecha de Ingreso: diciembre-2008
Mensajes: 216
Antigüedad: 15 años, 4 meses
Puntos: 2
Respuesta: no detecta ID

http://clubice.site50.net/eje/

Edito: ya corregi los 2 errores, jajajaja como siempre surgue otro proble: no se por que, pero me dice que:
Error: this.frames[this.count] is undefined
Archivo de origen: http://localhost/icepokemon/index.htm
Línea: 66
si lo unico que hize fue cambiar la funcion Sprite():

Código Javascript:
Ver original
  1. <HTML>
  2.  <HEAD>
  3.   <TITLE>Ice Pokemon</TITLE>
  4.   <SCRIPT>
  5. Object.prototype.initialize = function(init){for(var prop in init)if(init.hasOwnProperty(prop)) this[prop] = init[prop];}
  6. $=function(i) {return document.getElementById(i)}
  7.  
  8. Sprite=function(image,width,height,hmargin,vmargin,hspace,vspace,rows,cols) {
  9.  this.numItems=rows*cols;
  10.  this.image=new Image()
  11.  this.image.src=image;
  12.  this.frames=new Array();
  13.  count=0;
  14.  for (i=0; i<cols; i++) {
  15.   for (j=0; j<rows; j++) {
  16.    x=vmargin+(width*j)+(vspace*j)
  17.    y=hmargin+(height*i)+(hspace*i)
  18.    this.frames[count]={x:x,y:y}
  19.    count++
  20.   }
  21.  }
  22.  this.height=height;
  23.  this.width=width
  24. }
  25.  
  26. Animation=function(spr,spd) {
  27.  this.initialize({
  28.   sprite:spr,
  29.   speed:spd,
  30.   frames:[],
  31.   timer:null,
  32.   count:0,
  33.   id:null
  34.  });
  35. }
  36. Animation.prototype={
  37.  addFrame: function (id) {
  38.   spr=this
  39.   alert(id)
  40.   i=(this.frames.length==0)? 0: this.frames.length++
  41.   alert(i)
  42.   this.frames[i]={
  43.    id:id,
  44.    sprite:"url('"+spr.sprite.image.src+"') -"+spr.sprite.frames[id].x+"px -"+spr.sprite.frames[id].y+"px"
  45.   }
  46.  },
  47.  drawAnimation:function (con, id) {
  48.   image=document.createElement('img')
  49.   image.setAttribute('src','sprites/empy.gif')
  50.   image.setAttribute('style',"background:"+this.frames[0].sprite)
  51.   image.setAttribute('class','animation')
  52.   image.setAttribute('width',this.sprite.width)
  53.   image.setAttribute('height',this.sprite.height)
  54.   image.setAttribute('id',id)
  55.   con.appendChild(image)
  56.   this.id=image
  57.   var that = this;
  58.   this.timer=setInterval(function(){that.play();},this.speed);
  59.  },
  60.  play:function() {
  61.   if (this.count==this.frames.length) {
  62.    this.count=0
  63.   } else {
  64.    this.count++
  65.   }
  66.   this.id.style.background=this.frames[this.count].sprite
  67.  }
  68. }
  69. avatar=new Sprite('sprites/avatars/ash_walking.gif',30,38,0,0,0,0,1,12);
  70. aniAvatar=new Animation(avatar,100);
  71. aniAvatar.addFrame(0);
  72. aniAvatar.addFrame(1);
  73. aniAvatar.addFrame(0);
  74. aniAvatar.addFrame(2);
  75. window.onload=function() {aniAvatar.drawAnimation($('con'),'IMGavatar')}
  76.  
  77.   </SCRIPT>
  78.  </HEAD>
  79.  <BODY>
  80.  <DIV ID="con"></DIV>
  81.  </BODY>
  82. </HTML>

Última edición por ClubIce; 31/01/2010 a las 18:42
  #14 (permalink)  
Antiguo 31/01/2010, 18:38
Avatar de zerokilled
Javascripter
 
Fecha de Ingreso: abril-2009
Ubicación: Isla del Encanto, La Borinqueña [+>==]
Mensajes: 8.050
Antigüedad: 15 años
Puntos: 1485
Respuesta: no detecta ID

a esto era lo que me referia
Código:
   x=vmargin+(width*j)+(vspace*j)
   y=hmargin+(height*i)+(hspace*i)
y la imagen que utilice, http://img138.imageshack.us/img138/9084/palettev.gif
__________________
la maldad es una virtud humana,
y la espiritualidad es la lucha del hombre contra su maldad.
  #15 (permalink)  
Antiguo 31/01/2010, 18:46
Avatar de ClubIce  
Fecha de Ingreso: diciembre-2008
Mensajes: 216
Antigüedad: 15 años, 4 meses
Puntos: 2
Respuesta: no detecta ID

mira arriba
  #16 (permalink)  
Antiguo 31/01/2010, 19:43
Avatar de zerokilled
Javascripter
 
Fecha de Ingreso: abril-2009
Ubicación: Isla del Encanto, La Borinqueña [+>==]
Mensajes: 8.050
Antigüedad: 15 años
Puntos: 1485
Respuesta: no detecta ID

el error se debe a que estas haciendo referencia a un elemento del array frames que no existe. el error se lanza desde la funcion play. te dejo una pista, preguntate que sucede cuando this.count equivale a tres. por cierto, puedes reducir varias lineas de esa funcion usando el operador modulo (%), y por ende te evitas el error que tienes ahora mismo.
__________________
la maldad es una virtud humana,
y la espiritualidad es la lucha del hombre contra su maldad.
  #17 (permalink)  
Antiguo 31/01/2010, 21:29
Avatar de ClubIce  
Fecha de Ingreso: diciembre-2008
Mensajes: 216
Antigüedad: 15 años, 4 meses
Puntos: 2
Respuesta: no detecta ID

explicame eso del %, es que yo nunca lo he usado .
  #18 (permalink)  
Antiguo 31/01/2010, 21:38
Avatar de zerokilled
Javascripter
 
Fecha de Ingreso: abril-2009
Ubicación: Isla del Encanto, La Borinqueña [+>==]
Mensajes: 8.050
Antigüedad: 15 años
Puntos: 1485
Respuesta: no detecta ID

el operador modulo te devuelve el sobrante de una division. por ejemplo, 5 % 2 = 1. es decir, no es la mejor ilustracion pero bueno...
Código:
  2   
2 | 5
   =4
   1
__________________
la maldad es una virtud humana,
y la espiritualidad es la lucha del hombre contra su maldad.
  #19 (permalink)  
Antiguo 31/01/2010, 22:10
Avatar de ClubIce  
Fecha de Ingreso: diciembre-2008
Mensajes: 216
Antigüedad: 15 años, 4 meses
Puntos: 2
Respuesta: no detecta ID

definitivamente no encuentro la falla. Podrias darme otra pista o explicarmelo mejor

PD: hablo del array no del %
  #20 (permalink)  
Antiguo 31/01/2010, 22:15
Avatar de zerokilled
Javascripter
 
Fecha de Ingreso: abril-2009
Ubicación: Isla del Encanto, La Borinqueña [+>==]
Mensajes: 8.050
Antigüedad: 15 años
Puntos: 1485
Respuesta: no detecta ID

tal como lo tienes ahora mismo, mas o menos esto es lo que sucede. si tu array tiene 4 elementos y this.count equivale a 3, entonces se interpreta de esta forma. ¿es tres igual a 4? no. entonces agrega uno a this.count, por tanto equivale a 4. luego, cuando se asigna el valor a la propiedad background, esta añadiendo el 5to elemento del array, el cual no existe. la idea es valida pero no en ese orden.
__________________
la maldad es una virtud humana,
y la espiritualidad es la lucha del hombre contra su maldad.
  #21 (permalink)  
Antiguo 31/01/2010, 23:25
Avatar de ClubIce  
Fecha de Ingreso: diciembre-2008
Mensajes: 216
Antigüedad: 15 años, 4 meses
Puntos: 2
Respuesta: no detecta ID

lo que hize ahora fue igualar thus.count con frames.length, pero ahora no se porque no se mueve, ni tampoco me muertra ningun error:
Código Javascript:
Ver original
  1. <HTML>
  2.  <HEAD>
  3.   <TITLE>Ice Pokemon</TITLE>
  4.   <SCRIPT>
  5. Object.prototype.initialize = function(init){for(var prop in init)if(init.hasOwnProperty(prop)) this[prop] = init[prop];}
  6. $=function(i) {return document.getElementById(i)}
  7.  
  8. Sprite=function(image,width,height,hmargin,vmargin,hspace,vspace,rows,cols) {
  9.  this.numItems=rows*cols;
  10.  this.image=new Image()
  11.  this.image.src=image;
  12.  this.frames=new Array();
  13.  count=0;
  14.  for (i=0; i<cols; i++) {
  15.   for (j=0; j<rows; j++) {
  16.    x=vmargin+(width*j)+(vspace*j)
  17.    y=hmargin+(height*i)+(hspace*i)
  18.    this.frames[count]={x:x,y:y}
  19.    count++
  20.   }
  21.  }
  22.  this.height=height;
  23.  this.width=width
  24. }
  25.  
  26. Animation=function(spr,spd) {
  27.  this.initialize({
  28.   sprite:spr,
  29.   speed:spd,
  30.   frames:[],
  31.   timer:null,
  32.   count:0,
  33.   id:null
  34.  });
  35. }
  36. Animation.prototype={
  37.  addFrame: function (id) {
  38.   spr=this
  39.   i=(!this.frames.length)? 0: this.frames.length++
  40.   this.frames[i]={
  41.    id:id,
  42.    sprite:"url('"+spr.sprite.image.src+"') -"+spr.sprite.frames[id].x+"px -"+spr.sprite.frames[id].y+"px"
  43.   }
  44.  },
  45.  drawAnimation:function (con, id) {
  46.   image=document.createElement('img')
  47.   image.setAttribute('src','sprites/empy.gif')
  48.   image.setAttribute('style',"background:"+this.frames[0].sprite)
  49.   image.setAttribute('class','animation')
  50.   image.setAttribute('width',this.sprite.width)
  51.   image.setAttribute('height',this.sprite.height)
  52.   image.setAttribute('id',id)
  53.   con.appendChild(image)
  54.   this.id=image
  55.   var that = this;
  56.   this.timer=setInterval(function(){that.play();},this.speed);
  57.  },
  58.  play:function() {
  59.   //this.count=(this.count==this.frames.length)? 0:this.count++
  60.   this.id.style.background=this.frames[this.count].sprite
  61.   if (this.count==this.frames.length-1) {this.count=0} else {this.count++}
  62.  }
  63. }
  64. avatar=new Sprite('sprites/avatars/ash_walking.gif',30,38,0,0,0,0,1,12);
  65. aniAvatar=new Animation(avatar,100);
  66. aniAvatar.addFrame(0);
  67. aniAvatar.addFrame(1);
  68. aniAvatar.addFrame(0);
  69. aniAvatar.addFrame(2);
  70. window.onload=function() {aniAvatar.drawAnimation($('con'),'IMGavatar')}
  71.  
  72.   </SCRIPT>
  73.  </HEAD>
  74.  <BODY>
  75.  <DIV ID="con"></DIV>
  76.  </BODY>
  77. </HTML>
  #22 (permalink)  
Antiguo 01/02/2010, 00:15
Avatar de ClubIce  
Fecha de Ingreso: diciembre-2008
Mensajes: 216
Antigüedad: 15 años, 4 meses
Puntos: 2
Respuesta: no detecta ID

porfin lo logre. ahora ya puedo pasar al siguiente paso: crear Sprites masivamente XD

Muchas gacias por tu ayuda

PD: dejo el script para que veas como lo hize:
Código Javascript:
Ver original
  1. <HTML>
  2.  <HEAD>
  3.   <TITLE>Ice Pokemon</TITLE>
  4.   <SCRIPT>
  5. Object.prototype.initialize = function(init){for(var prop in init)if(init.hasOwnProperty(prop)) this[prop] = init[prop];}
  6. $=function(i) {return document.getElementById(i)}
  7.  
  8. Sprite=function(image,width,height,hmargin,vmargin,hspace,vspace,rows,cols) {
  9.  this.numItems=rows*cols;
  10.  this.image=new Image()
  11.  this.image.src=image;
  12.  this.frames=new Array();
  13.  count=0;
  14.  for (i=0; i<cols; i++) {
  15.   for (j=0; j<rows; j++) {
  16.    y=hmargin+(height*j)+(hspace*j)
  17.    x=vmargin+(width*i)+(vspace*i)
  18.    this.frames[count]={x:x,y:y}
  19.    count++
  20.   }
  21.  }
  22.  this.height=height;
  23.  this.width=width
  24. }
  25.  
  26. Animation=function(spr,spd) {
  27.  this.initialize({
  28.   sprite:spr,
  29.   speed:spd,
  30.   frames:[],
  31.   timer:null,
  32.   count:0,
  33.   id:null
  34.  });
  35. }
  36. Animation.prototype={
  37.  addFrame: function (id) {
  38.   spr=this
  39.   i=(!this.frames.length)? 0: this.frames.length++
  40.   this.frames[i]={
  41.    id:id,
  42.    sprite:"url('"+spr.sprite.image.src+"') -"+spr.sprite.frames[id].x+"px -"+spr.sprite.frames[id].y+"px"
  43.   }
  44.  },
  45.  drawAnimation:function (con, id) {
  46.   image=document.createElement('img')
  47.   image.setAttribute('src','sprites/empy.gif')
  48.   image.setAttribute('style',"background:"+this.frames[0].sprite)
  49.   image.setAttribute('class','animation')
  50.   image.setAttribute('width',this.sprite.width)
  51.   image.setAttribute('height',this.sprite.height)
  52.   image.setAttribute('id',id)
  53.   con.appendChild(image)
  54.   this.id=image
  55.   var that = this;
  56.   this.timer=setInterval(function(){that.play();},this.speed);
  57.  },
  58.  play:function() {
  59.   //this.count=(this.count==this.frames.length)? 0:this.count++
  60.   this.id.style.background=this.frames[this.count].sprite
  61.   if (this.count==this.frames.length-1) {this.count=0} else {this.count++}
  62.  }
  63. }
  64. avatar=new Sprite('sprites/avatars/ash_walking.gif',30,38,0,0,0,0,1,12);
  65. aniAvatar=new Animation(avatar,1000);
  66. aniAvatar.addFrame(0);
  67. aniAvatar.addFrame(1);
  68. aniAvatar.addFrame(0);
  69. aniAvatar.addFrame(2);
  70. window.onload=function() {aniAvatar.drawAnimation($('con'),'IMGavatar')}
  71.  
  72.   </SCRIPT>
  73.  </HEAD>
  74.  <BODY>
  75.  <DIV ID="con"></DIV>
  76.  </BODY>
  77. </HTML>
  #23 (permalink)  
Antiguo 01/02/2010, 00:21
Avatar de zerokilled
Javascripter
 
Fecha de Ingreso: abril-2009
Ubicación: Isla del Encanto, La Borinqueña [+>==]
Mensajes: 8.050
Antigüedad: 15 años
Puntos: 1485
Respuesta: no detecta ID

ya iba a decir, no encuentro el problema porque a mi me estaba funcionando, solo que ahora tenia un patron diferente. igual revisare el ultimo codigo. por cierto, ahora te paso la factura: un jamon y par de cervezas.
__________________
la maldad es una virtud humana,
y la espiritualidad es la lucha del hombre contra su maldad.
  #24 (permalink)  
Antiguo 01/02/2010, 00:41
Avatar de ClubIce  
Fecha de Ingreso: diciembre-2008
Mensajes: 216
Antigüedad: 15 años, 4 meses
Puntos: 2
Respuesta: no detecta ID

Jajajajaja, no te preocupes tarde o temprano algun dia te pagare XD, te dejo mi msn para que estemos en contacto: [email protected]

Etiquetas: detecta
Atención: Estás leyendo un tema que no tiene actividad desde hace más de 6 MESES, te recomendamos abrir un Nuevo tema en lugar de responder al actual.
Respuesta




La zona horaria es GMT -6. Ahora son las 20:19.