Hello,
I had everything working fine in Unity 5.4, i upgraded to 5.6.0.f3 then ALL my javascript plug in code stopped working.
When an old style GUI button is pressed in the OnGUI function it calls the plugin function below
ImageUploaderCaptureClick, which should pop up a file dialog box allowing the user to select a photo. That was working before in 5.4.
But in 5.6 when the button is clicked there is an error like this:
Invoking error handler due to
Uncaught TypeError: Cannot read property ‘addEventListener’ of null
Seems the code below
document.getElementById(‘canvas’).addEventListener(‘click’, OpenFileDialog, false);
the ‘canvas’ element is missing, resulting in getElementById= null, then of course there is no addEventListener function from null.
anybody knows what happened to the ‘canvas’ that was there in 5.4 that is now mssing in 5.6?
All my javascript plugin code is using the canvas which is now missing in 5.6.
Here is sample code:
FILE=MyPlugin,jslib
var MyPlugin = {
ImageUploaderCaptureClick: function() {
if (!document.getElementById('ImageUploaderInput')) {
var fileInput = document.createElement('input');
fileInput.setAttribute('type', 'file');
fileInput.setAttribute('id', 'ImageUploaderInput');
fileInput.style.visibility = 'hidden';
fileInput.onclick = function (event) {
this.value = null;
};
fileInput.onchange = function (event) {
SendMessage('LocalLoginUpload', 'FileSelected', URL.createObjectURL(event.target.files[0]));
}
document.body.appendChild(fileInput);
}
var OpenFileDialog = function() {
document.getElementById('ImageUploaderInput').click();
document.getElementById('canvas').removeEventListener('click', OpenFileDialog);
};
document.getElementById('canvas').addEventListener('click', OpenFileDialog, false);
}
};
mergeInto(LibraryManager.library, MyPlugin);
I tried adding a canvas element in javascript near the top of the function i added this
var c=document.createElement('canvas');
c.id='canvas';
document.body.appendChild(c);
generates no errors, but it doesnt work, the onclick never fires which is what i use to trigger the open file dialog box to be displayed so that the user can select a picture from his computer to be used for his profile.
I have a lot of similar code which no longer works either, all of it worked in 5.4 now it doesnt work in 5.6. I spent so many hours to get it to work, now just by upgrading it doesnt work.
So now i cant do anything! Im stuck!
Anybody has ideas?
Thanks!