I have a function inside a function that I need to handle directly.
//############################################################# //# Global vars //############################################################# var canvasWidth = 585; var canvasHeight = 780; //############################################################# //# Init the canvas //############################################################# window.onload = function() { initStage(); }; //############################################################# //# Init the main stage //############################################################# function initStage() { //************************************************************* //* Create a stage to work with //************************************************************* var stage = new Kinetic.Stage({ container: "container", width: canvasWidth, height: canvasHeight }); var layerOne = new Kinetic.Layer(); var imageObj = new Image(); //************************************************************* //* Load the image into a layer on the stage //************************************************************* ... Some Code ... //************************************************************* //* Set the hidden field value to the canvas dataURL //************************************************************* function autoSave(){ stage.toDataURL({ callback: function(dataUrl){ document.getElementById("mapping-form:hiddenDataURL").value = dataUrl; console.log("Auto Save excecuted"); }, mimeType: 'image/jpeg', quality: 1.0 }); } //************************************************************* //* Function called to add text to the stage //************************************************************* ... Some Code ... layerTwo.add(txt); stage.add(layerTwo); }); }
I am trying to access autosave () (which requires the var step from the parent function). I understand why I can't access it, but I'm struggling to figure out how I can change the code to make it available.
My first thought was to simply declare a var "extended scope" and assign a function to it. The problem (as far as I can see) is that this actually does not allow me to execute autoSave () at the specified time.
I apologize for the "core point of this question, I am new to JS, and I think it will be fundamental!
source share