I can't access the 'members' of my polymer 'class'
Polymer({
is: 'sound-propagation',
time1: 0,
time2: 0,
timeDifference: 0,
timeCounter:0,
speed: 5,
distance: 5,
frequency: [],
amplitude: 15,
deflection: [],
animation: 0,
timeout: 0,
counter: 0,
appletStart: function(context, firstStart) {
this.initializeCircles();
this.changeFrequency(0.5);
this.setAnimation();
},
setAnimation: function(){
var self = this;
var timeout = setTimeout(function(){ console.log("frequencybla: "+self.frequency[6]);}, 3000);
this.animation = setInterval(function(){
if(self.counter >= 20){
self.time2 = Date.now();
self.timeDifference = (self.time2 - self.time1)/20000;
self.time1 = Date.now();
self.counter = 0;
}
for(var i = 0; i <=19; i+=1){
self.deflection[i] = self.amplitude*Math.sin(self.timeCounter*self.frequency[i]*2*Math.PI);
//console.log("deflection: "+self.deflection[i]);
//console.log("amplitude: "+self.amplitude);
//console.log("timeCounter: "+self.timeCounter);
//console.log("frequency: "+self.frequency[i]);
}
self.timeCounter += self.timeDifference;
self.counter += 1;
}, 1);
},
changeFrequency: function(newFrequency){
var self = this;
for(var i = 0; i <=19; i+=1){
//var timeout = setTimeout(function(){ self.setFrequency(i, newFrequency); console.log("frequencyTimeOut: "+self.frequency[i]);}, (this.distance/this.speed)*1*(i+1));
//this.setFrequency(i, newFrequency);
var timeout = setTimeout(function(){var j = i; self.frequency[j]=newFrequency; console.log("frequencyTimeOut: "+self.frequency[i]);}, 1000);
}
}
I'm trying to set the value of my outermost frequency array inside of a timeout function, and access this value inside of the animation interval. but it seems like the values aren't stored in the right array, when i print out the value in the console it is undefined. Could someone explain me how to specify the right array inside of my timeout function?
I left out some of the code, because i thought it isn't important.