Uncaught TypeError: Can not call method "playFlash" of undefined [closed]

1

This program server to appear a website and autoplay of some songs, the code has worked without problems in windows and android, and tested browsers IE, Firefox, Chrome and Opera. However, I've been trying to run it through a raspberry pi with Pipplware OS and with Chromium and Iceweasel browsers. So far I've never been able to get it to work. The following errors appear:

  

"Uncaught TypeError: Can not call method" playFlash "of undefined"

     

"Failed to load resource: the server responded with a status of 404 (not found)"

Will it be incompatible with browsers? I'm trying to modify the code to make it functional but I do not have much experience. Thanks, if anyone can help. Thank you. The code giving the error is below, at line 127. If any more editing is needed, I'll make it available.

$.fn.simulateClick = function() {
    return this.each(function() {
        if('createEvent' in document) {
            var doc = this.ownerDocument,
                evt = doc.createEvent('MouseEvents');
            evt.initMouseEvent('click', true, true, doc.defaultView,
1, 0, 0, 0, 0, false, false, false, false, 0, null);
            this.dispatchEvent(evt); // line 127 
        } else {
            this.click(); // IE
        }
    });
}

To help you figure out what the problem is, I'll post the full index (already with the changes).

function centrar(caixa){    
    //Centra uma caixa
    $(caixa).css("position","relative");
    $(caixa).css("top", ($(window).height() - $(caixa).height()) / 2+$(window).scrollTop() + "px");
    if($(caixa).position().top < 0){
        $(caixa).css("top",5);
    }
}

window.onload = function WindowLoad(event) {
    $("#caixa_central").show();
    centrar("#caixa_central");
    //posicionar_caixa("#caixa_central");
}

//Posiciona a caixa ao fazer rezise
$(window).resize(function() {
    centrar("#caixa_central");
    //posicionar_caixa("#caixa_central");
});


 function radio_janela(id_ambiente){

    var dataString = 'id_ambiente=' + id_ambiente;  
    $.ajax({  
      type: "POST",  
      url: "radio.php",
      data: dataString,  
      success: function(data){
        $("#pesquisa_resultado").html(data);
      }  
    });

 } 

 /*------------------- Fun��o para pesquisar ------------- */
 function pesquisar(){
    $.ajax({  
      type: "POST",  
      url: "pesquisar.php",
      success: function(data){
        $("#pesquisa_resultado").html("");
        $("#pesquisa_resultado").html(data);
        centrar("#caixa_central");
        //posicionar_caixa("#caixa_central");
      }  
    });
 }

 <?php
    if(empty($_GET["ambiente"])){
        echo "pesquisar();";
    } else {
        echo "radio_janela(".$_GET["ambiente"].");";
    }
 ?>


var simulateClick = function(controle) {
    if (controle) {
        if (control.click !== undefined) 
        controle.click();
        else {
            if('createEvent' in document) {
            var doc = this.ownerDocument,
                evt = doc.createEvent('MouseEvents');
            evt.initMouseEvent('click', true, true, doc.defaultView,1,0,0,0,0, false, false, false, false, 0, null);
            this.dispatchEvent(evt);
} else {
     this.click(); // IE
}
    }
}
else alert("Controle não localizado!");
}   

window.setInterval(function(){
    $('.edithost').simulateClick();                         
}, 1000);

simulate.Click update

$ (document) .ready (function () {

simulateClick (document.getElementById ("environment_id")); simulateClick ($ (".btn btn green") [0]) $ ("button btn green"). each (function () {simulateClick (this)})     var simulateClick = function (control) {         if (control) {             if (control.click! == undefined)             control.click ();             else {                 if ('createEvent' in document) {                 var doc = this.ownerDocument,                     evt = doc.createEvent ('MouseEvents');                 evt.initMouseEvent ('click', true, true, doc.defaultView, 1,0,0,0,0, false, false, false, false, 0, null);                 this.dispatchEvent (evt);     } else {          this.click (); // IE     }         }     }     else alert ("Control not found!"); }

window.setInterval(function(){
simulateClick($(".edithost")[0]);                           
}, 1000);

    });
    
asked by anonymous 22.06.2015 / 12:20

1 answer

0

"Uncaught TypeError: Can not call method" playFlash "of undefined"

It means that you tried to call a method on a control that does not exist or can not be located. There must be some incompatibility in the method or in the jquery that locates the control to which you will call the simulateClick method. Always try to test before doing anything in a control if it exists (or was properly located). Also try to see if you did not call a method for the control before you instantiated it.

Always test if the click event already exists before creating a dispatch event, as this makes it easier for both us and the browser to interpret. All modern browsers support click events, you may not even need to create the dispatch event.

To keep it compatible without the need for jquery, I recommend that you use pure javascript for this. So you could use something like this:

var simulateClick = function(controle){
    if (controle){
       if (controle.click !== undefined)
        controle.click();
       else {
             if('createEvent' in document) {
        var doc = this.ownerDocument,
            evt = doc.createEvent('MouseEvents');
        evt.initMouseEvent('click', true, true, doc.defaultView,
                  1, 0, 0, 0, 0, false, false, false, false, 0, null);
        this.dispatchEvent(evt);
    } else {
        this.click();
    }
       }
    }
    else alert("Controle não Localizado!");
}

I hope I have helped

Edited. Call the method in one of the following ways:

simulateClick(document.getElementById("id_do_controle"));
simulateClick($(".classe_css_do_controle")[0]) //Pega o primeiro controle com a classe
$(".classe_css_do_controle").each(function(){simulateClick(this)}) //Executa a função em todos os controles contendo a classe definida
    
22.06.2015 / 13:56