This question refers to kineticJS but the problem is about the basic logic of nested functions I believe. I have a kineticjs stage on a div:
<div id="container"></div>
The kineticjs script puts a shape on the stage:
function displayVizualization(){
//SKETCH SIZE
var SKETCH_WIDTH = 800;
var SKETCH_HEIGTH = 800;
var stage = new Kinetic.Stage({
container: document.getElementById('container'),
width: SKETCH_WIDTH,
height: SKETCH_HEIGTH
});
var layer = new Kinetic.Layer();
var rect = new Kinetic.Rect({
x: 239,
y: 75,
width: 100,
height: 50,
fill: 'green',
stroke: 'black',
strokeWidth: 4
});
// add the shape to the layer
layer.add(rect);
// add the layer to the stage
stage.add(layer);
function updateViz(){
console.log("we are in the updateViz function")
var count = document.getElementById("formID:counter").value;
console.log("count is: "+count);
rect.transitionTo({
x: 100*count,
duration: 2,
easing: easing
});
}
}
I need to call the function "updateViz" from another script on this page in an oncomplete attribute. I have something that says:
oncomplete: updateViz();
But of course I get an "function not defined" error because updateViz() is nested in displayVizualization().
How should I call updateViz() then? Thx!
[EDIT: moving updateViz() outside displayVisualization() is perfectly fine with me. But then please explain how the variables in updateViz should refer to the variables in displayVisualization?]