Uncaught Referenceerror: takepic is not defined (Intel XDK)

Asked

Viewed 138 times

0

I saw on the internet an example to capture photo in the app. I am debugging and appears this error:

Uncaught Referenceerror: takepic is not defined

My code:

function takepic(){
        intel.xdk.camera.takePicture(10,true, "jpg");
    }
    document.addEventListener("intel.xdk.camera.picture.add", function(event){
        var nomeFoto = event.filename;
        var url = intel.xdk.camera.getPictureURL(nomeFoto);
        document.getElementById("ocorrenciaFoto1").setAttribute("src", url);
    });

Button that makes the action:

<button onclick="takepic()" class="btn widget uib_w_50 d-margins btn-lg btn-primary" data-uib="twitter%20bootstrap/button" data-ver="1"><i class="glyphicon glyphicon-camera button-icon-top" data-position="top"></i>Foto</button>

What is wrong?

  • Try putting it on instead of onclick in html, a .addEventListener("click", takepic) on the button, in javascript. It is important the function come without parentheses.

  • @Samirbraga you could post the code as it should below?

  • Of course, it’s not certain to function, but it doesn’t hurt to try.

1 answer

1


Try it like this:

function takepic() {
  intel.xdk.camera.takePicture(10, true, "jpg");
}
document.addEventListener("intel.xdk.camera.picture.add", function(event) {
  var nomeFoto = event.filename;
  var url = intel.xdk.camera.getPictureURL(nomeFoto);
  document.getElementById("ocorrenciaFoto1").setAttribute("src", url);
});
var button = document.getElementById("takeAPicture");
button.addEventListener("click", takepic);

Add a id="takeAPicture" on your button and remove the onclick="takepic()".

Browser other questions tagged

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