Hi.

Originally Posted by
aaron.martone
I'd recommend making the "current" vairable global.
[...]
Eh?
Thank you for your answer 
What you posted is more or less what I have come up with. I didn't make current global but this does not seem to be the problem. I will post a simplified version of the code I have:
Code:
// "global" values for drawing the lines
var xoffset = 10;
var yoffset = 10;
var between = 10;
var scaley = 1.5;
var ROUNDS = 25;
var current = 0;
// two records
var records = new Array(0, 12, 8, 12, 20, -10, 30, 12, 40, -20, -14, -10, 8, 4, 0);
var records2 = new Array(0, 14, 2, 1, 30, -1, 23, 32, 43, -20, -30, -10, 3, 4, 0);
// implementation of Java's drawline
MovieClip.prototype.drawLine = function(x1, y1, x2, y2) {
this.moveTo(x1, y1);
this.lineTo(x2, y2);
}
// plot data which is stored in an array
MovieClip.prototype.plotData = function(records) {
for (var i = 0; i < Math.min(current, records.length); i++) {
// the next point in the array
var j = Math.min(i + 1, records.length - 1);
this.drawLine(
i * between,
scaley * -records[i],
j * between,
scaley * -records[j]
);
}
}
// create to movie clips
var plot1 = _root.createEmptyMovieClip("p1", 1);
var plot2 = _root.createEmptyMovieClip("p2", 2);
plot1.lineStyle(1, 0xFF0000, 100);
plot2.lineStyle(1, 0x00FF00, 100);
plot1._x = xoffset;
plot1._y = 40;
plot2._x = xoffset;
plot2._y = 40;
plot1.plotData(records);
plot2.plotData(records2);
And this is the code for [previous] and [next] buttons I use:
previous:
Code:
on(release) {
current = Math.max(0, current - 1);
plot1.plotData(records);
plot2.plotData(records2);
}
next:
Code:
on(release) {
current = Math.min(current + 1, ROUNDS);
plot1.plotData(records);
plot2.plotData(records2);
}
Now when I click on next (the second button in the attached file, the next points are drawn. However clicking on previous (first button) it doesn't go back.
Perhaps I have to clear the already drawn lines and display these afterwards?
Thanks,
Christian
Bookmarks