Foros del Web » Creando para Internet » HTML »

no cambia el src de imagen en evento oclick agregado poo javascript

Estas en el tema de no cambia el src de imagen en evento oclick agregado poo javascript en el foro de HTML en Foros del Web. Hola es que tengo este code pero no me funciona la llamada a una funcion que hago desde un evento en un clase: el code: ...
  #1 (permalink)  
Antiguo 06/07/2012, 14:34
Avatar de gilber966  
Fecha de Ingreso: abril-2010
Mensajes: 117
Antigüedad: 14 años
Puntos: 4
no cambia el src de imagen en evento oclick agregado poo javascript

Hola es que tengo este code pero no me funciona la llamada a una funcion que hago desde un evento en un clase:

el code:


Código Javascript:
Ver original
  1. (function(){
  2.  
  3.     var random = window.random = function(min, max){
  4.         var rango_superior = max,
  5.             rango_inferior = min,
  6.             aleatorio = Math.floor(Math.random()*(rango_superior-(rango_inferior-1))) + rango_inferior;
  7.            
  8.         return aleatorio;
  9.     }
  10.  
  11.  
  12.     var idCount = 0;
  13.     var protagonista = window.protagonista = function(){
  14.    
  15.         // atributos
  16.         this.posY=0;
  17.         this.caida;
  18.         this.modo="";
  19.         this.tramos=4;
  20.         this.vidas=5;
  21.         this.paracaidas=false; 
  22.         this.id = "imgSold" + idCount;
  23.         idCount++;
  24.        
  25.         this.ele= document.createElement('img');
  26.         this.ele.src = 'amigo-normal-1.png';
  27.         this.ele.id = this.id;
  28.         this.ele.className = "sold";
  29.         this.ele.onclick = function(e){
  30.                        alert('obtuve el evento click');//este alert si me funciona
  31.             this.ele.src = "amigo-cayendo-1.png";//aqui no hace nada
  32.         };
  33.         document.getElementById("main").appendChild(this.ele);
  34.        
  35.         // metodos
  36.             this.iniciar = function(posx){
  37. //alert(posx);
  38.             var self = this;           
  39.             this.mostrar();
  40.             this.posX=posx;
  41.             this.ele.style.left= String(this.posX) + "px";
  42.             this.caida=setTimeout(function () { self.caer(); }, 50);
  43.            
  44.         }
  45.        
  46.         this.mostrar = function(){
  47.             this.ele.style.visibility="visible";
  48.         };
  49.        
  50.         this.ocultar = function(){
  51.             this.ele.style.visibility="Hidden";
  52.         };
  53.        
  54.         this.caer = function (){
  55.            
  56.             this.posY = this.posY + this.tramos;
  57.            
  58.             if(this.posY<=520){
  59.                 this.ele.style.top= String(this.posY) + "px";
  60.                 //this.ele.style.left= String(this.posX) + "px";               
  61.                 //document.getElementById('py').value=vel;
  62.                 //console.log("this.posY: " + this.posY);
  63.                 var self = this;
  64.                 this.caida=setTimeout(function () { self.caer(); }, 50);
  65.             }
  66.             else{
  67.                 clearTimeout(this.caida);
  68.                 this.posY=0;
  69.                 //alert("termine de caer");
  70.                 this.ele.src ="amigo-caminando-1.gif";                 
  71.                 if(paracaidas==false){
  72.                     this.ocultar();
  73.                     this.vidas=this.vidas-1;
  74.                     document.getElementById('vidas').value=this.vidas;
  75.                 }              
  76.             }
  77.         }
  78.         this.abrirParacaidas = function(){
  79.             this.ele.src = "amigo-cayendo-1.png";
  80.            
  81.         };
  82.        
  83.        
  84.     };
  85.  
  86. })();

Etiquetas: agregado, evento, javascript, poo, src, cambios
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 14:01.