我正在尝试使用event.count更改矩形的宽度。 但是我没有从onFrame函数中找到变量“thewidth”。
我试过这个.path.thewidth / thewidth / myLine.thewidth .....都给出错误“thewidth not defined”。
(我是新手,并且正在努力完成必须的基本任务)
任何指针都感激不尽。
var growLine = Backbone.Model.extend({
initialize: function() {
this.initialPosition = new paper.Point(20,60);
var thewidth = 2;
var theheight =2;
this.path = new paper.Path.Rectangle(new paper.Point(748, 270), thewidth, theheight);
this.path.strokeColor = 'green';
this.animationStartFrame = null;
this.path.model = this;
this.activated = false;
},
trigger: function() {
this.activated = !this.activated;
if(this.activated)
this.path.fillColor = 'red';
toggleOnFrameListener(this, this.onFrame.bind(this.path));
},
onFrame: function(event) {
if(this.animationStartFrame == null)
this.animationStartFrame = event.count;
var animationFrame = event.count - this.animationStartFrame;
console.log(thewidth);
}
});
答案 0 :(得分:0)
thewidth在函数内定义,并且是该函数的本地。您将需要声明this.thewidth,使其成为全局,或提供另一种方式来访问该值,以便在声明它的函数范围之外引用它。