Uncaught Typeerror: Cannot call method "playFlash" of Undefined

Asked

Viewed 54 times

1

This server program to pop up a website and autoplay a few songs, the code has run smoothly on windows and android, and the browsers tested form the IE, Firefox, Chrome and Opera. However, I have been trying to run it through a pi Raspberry with the Pipplware OS and the Chromium and Iceweasel browsers. So far I have never been able to get it to work. The following errors appear:

"Uncaught Typeerror: Cannot call method "playFlash" of Undefined"

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

Is it incompatible with browsers? I’m trying to modify the code in a way that makes it functional but I don’t have much experience. Thank you if anyone can help. Thank you. The error code is below on line 127. If further editing is required, I will make 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 understand what the problem is, I will 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("id_ambiente")); simulateClick($(".button 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, 0, null); this.dispatchEvent(evt); } Else { this.click(); // IE } } } Else Alert("Control not located!"); }

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

    });
  • By mistake 404 went wrong, could not recover anything from server.

  • @Maicon Carraro Because, mysql came with some errors initially, along with phpmyadmin, could that also be the case? Some I managed to solve, others not so much. But mysql connecta and works, I just don’t know if it’s 100% or if it’s actually preventing javascript from working. The last mistakes that I was to solve neither conse Gui, because they were terms in which the only solution was "depricated" and there is still no substitute, which is the case of the "can t ceate test file..." and "Can t change dir ...".

1 answer

0

"Uncaught Typeerror: Cannot call method "playFlash" of Undefined"

It means that you tried to call a method in a control that does not exist or cannot be located. There must be some incompatibility in the method or in the jquery that locates the control you will call the simulateClick method. Always try to test before doing anything on a control if the same is happening (or has been properly located). Also try to see if you didn’t call a control method before you instantiated it (created).

Always test before if there is already a click event before creating an event in Dispatch, 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 using 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’ve 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
  • Thank you very much for the reply, it was very thorough and well explained. I changed code as suggested, however now more errors appear, "Uncaught Typeerror: Object [Object Object] has no method 'simulateClick'. I noticed that there is one more piece of code that matches the function, but I don’t think it influences, the errors continue to come from dispatchEvent(evt);. window.setInterval(function(){$('.edithost').simulateClick();}, 1000);

  • I’ve also searched and I haven’t noticed any methods that haven’t been developed beforehand, but as I said, I don’t have much experience. I’ll edit the question and put the full index file.

  • Change the $('.edithost'). simulateClick(); Para simulateClick($(".edithost")[0]) if it is just a control Ou $(".edithost"). each(Function(){simulateClick(this)}) if it is more than one

  • If you can post the html of this(s) controls on which you want to simulate the click. Why do you need this timeout to click? If you are trying to run something after loading the page, try $(Document). ready(Function(){//Code to run}) instead

  • I apologize for the delay in responding, but my trainee tutor thought it best to switch from OS to Raspberry. As soon as I test everything and if it comes back to the same, I follow the instructions you provided. Thank you very much for the support, it was very helpful.

  • Okay, I’ve got Raspbian installed, but except for a few incompatibilities, the bugs came up exactly the same. I already modified the code you told me to change and now only an error appears >Uncaught Typeerror: Undefined is not a Function on the line simulate.Click(document.getElementById("id_ambient")); Replace with control class as said, and also tried out such code that suggested me to run after page loading.

  • Try using only simulateClick(Document.getElementById("id_ambient"); Pois Simulate. Click(Document.getElementById("id_ambient"); Will search for a function named Click on a non-existent Simulate object. This point after Simulate must be generating the exception

Show 2 more comments

Browser other questions tagged

You are not signed in. Login or sign up in order to post.