这个问题是指 kineticJS 但问题是关于我相信的嵌套函数的基本逻辑。我在 div 上有一个 kineticjs 阶段:
<div id="container"></div>
kineticjs 脚本在舞台上放置了一个形状:
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
});
}
}
我需要在此页面上的另一个脚本中以 oncomplete 属性调用函数“updateViz”。我有句话说:
oncomplete: updateViz();
但是我当然会收到“函数未定义”错误,因为 updateViz() 嵌套在 displayVizualization() 中。
那我应该如何调用 updateViz() 呢?谢谢!
[编辑:将 updateViz() 移到 displayVisualization() 之外对我来说非常好。但是请解释一下 updateViz 中的变量应该如何引用 displayVisualization 中的变量?]