How do I open browser dialog to load without NW.JS/FileChoos

Get help using Construct 2

Post » Thu Feb 22, 2018 1:12 pm

How can i open the browser dialog to load an image without use the NW.JS plugin or the "File Chooser" plugin wich is a form control ?.

I tried to look in the browser actions but only appears "invoke download" to open the browse dialog to save some file but can't find the one for load to be used in the online version without form controls ¿?.

Maybe i guess i should use "execute javascript" but can't find any code to do that. Any idea?
Posts: 667
Reputation: 4,974

Post » Thu Feb 22, 2018 4:58 pm

Well seems i have a solution. Provided by @dop2000 .

Loading a .txt with ajax plugin with this content:

Code: Select all
var global = Function('return this')(); //get global scope.

global.openFileDialog = function(fileType) {
 // this function must be called from  a user
 // activation event (ie an onclick event)

    // Create an input element
    var inputElement = document.createElement("input");

    // Set its type to file
    inputElement.type = "file";

    // Set accept to the file types you want the user to select.
    // Include both the file extension and the mime type
    inputElement.accept = fileType;

    // set onchange event to call callback when user has selected file
    inputElement.addEventListener("change", function (event) {

    [...this.files].forEach(file => {
        //var s =;
var url = URL.createObjectURL(file);
        c2_callFunction("GetFileFromDialog", [url]);

     } );

    // dispatch a click event to open the file dialog
    inputElement.dispatchEvent(new MouseEvent("click"));

An execute javascript with "openFileDialog();" on sprite clicked or whatever.

Is a bit of workaround but seems works on any browsers and NW.JS.

If somebody know another solution/way, let me know.
Posts: 667
Reputation: 4,974

Return to How do I....?

Who is online

Users browsing this forum: Google [Bot] and 26 guests