codice:
tot = "3";
day_1 = "8;17;24;27;28;29;29;33;34;55;68";
day_2 = "12;17;18;21;23;24;25;27;35;45;57";
day_3 = "18;28;29;32;34;34;35;39;47;69;101";
function createFrame(width, height)
{
var mc = this.createEmptyMovieClip("frame_mc", 1);
mc.lineStyle(1, 0, 100);
mc.lineTo(width, 0);
mc.lineTo(width, height);
mc.lineTo(0, height);
mc.lineTo(0, 0);
}
function createButtonBase(clip)
{
clip.lineStyle(0, 0, 100);
clip.beginFill(0xFFCC00, 100);
clip.lineTo(80, 0);
clip.lineTo(80, 20);
clip.lineTo(0, 20);
clip.lineTo(0, 0);
clip.endFill();
}
function createBar(clip, width, height, col)
{
clip.lineStyle(0, 0, 100);
clip.beginFill(col, 100);
clip.lineTo(width, 0);
clip.lineTo(width, height);
clip.lineTo(0, height);
clip.lineTo(0, 0);
clip.endFill();
}
function createInnerText(clip, text)
{
clip.createTextField("testo", 1, 0, 0, 1, 1);
clip.testo.autoSize = "left";
clip.testo.text = text;
clip.testo._x = (clip._width / 2) - (clip.testo._width / 2);
clip.testo._y = (clip._height/ 2) - (clip.testo._height/ 2);
}
function createBars(data)
{
var data_array = data.split(";");
var data_len = data_array.length;
var avail_space = (frame_wdt - 4) - ((data_len - 1) * 2);
var width = avail_space / data_len;
for(var i = 0; i < data_len; i++){
var mc = frame_mc.createEmptyMovieClip("bar" + i, i);
createBar(mc, width, Number(data_array[i]) * 2, 0xFF0000);
mc._x = (i * (width + 2)) + 2;
mc._y = frame_hgt - mc._height;
createInnerText(mc, data_array[i]);
}
}
function createButtons(days, x, y)
{
for(var i = 1; i < days + 1; i++){
var mc = this.createEmptyMovieClip("button" + i, i + 100);
createBar(mc, 80, 20, 0xFFCC00);
mc._x = x + ((i - 1) * 100);
mc._y = y;
createInnerText(mc, "giorno " + i);
mc.id = i;
mc.onRelease = function()
{
this._parent.createBars(this._parent["day_" + this.id]);
}
}
}
function init()
{
frame_wdt = 400;
frame_hgt = 300;
createFrame(frame_wdt, frame_hgt);
createButtons(Number(tot), 0, frame_hgt + 10);
}
init();