Salve a tutti,
ho un problema con un action script, che genera un grafico a barre.
Il problema è che non riesco a far visualizzare il valore di ogni barra sopra la stessa, con zone di testo variabili.
l'action è questo
[I]
// make a 100-pixel grid movieclip at depth 1
lv= new LoadVars();
var color:Array= new Array(0x0066cc,0x999900,0x660099,0xcc0099,0x339900 ,0x00ff1e,0xea00ff,0x4926D9,0xFF0000,0x4498BB);
var len:Number= color.length;
var rnd:Number= Math.floor(Math.random()*len);
var randomColor= color[rnd];
var format:TextFormat = new TextFormat();
format.align = "justify";
format.color = 0x00ff00;
format.size = 14;
var nrSum:Number = 0;
//gradient fill data
fillType = "linear";
colors = [0xffffff, color[Number(Math.floor(Math.random()*len))]];
alphas = [100, 100];
ratios = [127, 255];
matrix = {matrixType:"box", x:30, y:50, w:30, h:30, r:0/180*Math.PI};
//end data gradient fill
createEmptyMovieClip("grid", 1);
grid.lineStyle(1, 0xcccccc, 100);
grid.moveTo(5, 5);
grid.lineTo(795, 5);
grid.lineTo(795, 400);
grid.lineTo(5, 400);
grid.lineTo(5, 5);
grid.moveTo(100, 5);
grid.lineTo(100, 400);
grid.moveTo(200, 5);
grid.lineTo(200, 400);
grid.moveTo(300, 5);
grid.lineTo(300, 400);
grid.moveTo(400, 5);
grid.lineTo(400, 400);
grid.moveTo(500, 5);
grid.lineTo(500, 400);
grid.moveTo(600, 5);
grid.lineTo(600, 400);
grid.moveTo(700, 5);
grid.lineTo(700, 400);
grid.moveTo(800, 5);
grid.lineTo(800, 400);
grid.moveTo(5, 100);
grid.lineTo(795, 100);
grid.moveTo(5, 200);
grid.lineTo(795, 200);
grid.moveTo(5, 300);
grid.lineTo(795, 300);
grid.moveTo(5, 400);
grid.lineTo(795, 400);
xinit=0;
x1=30;
y1=1;
// create a movieclip of two rectangles at depth 2
// create a variable r to reference this movieclip
// (which we can do because createEmptyMovieClip returns a
// reference to itself)
var r:MovieClip = createEmptyMovieClip("rectangles", 2);
//r.beginFill(0xcc00cc, 100);
//r.moveTo(30, 400);
//r.lineTo(50, 400);
//r.lineTo(50, 350);
//r.lineTo(30, 350);
// notice that the shape will be filled automatically
// without having to draw the last line
//r.endFill();
// start a new rectangle of a different color in the same clip
//r.beginFill(0x0000cc, 50);
//r.lineStyle(1, 0x000033, 100);
//r.moveTo(60, 400);
//r.lineTo(80, 400);
//r.lineTo(80, 180);
//r.lineTo(60, 180);
//r.endFill();
//var height:Array = new Array();
//for (var i:Number = 0; i < 10; i++) {
// height[i] = (i + 5) ;
//}
lv.onLoad = function(success:Boolean):Void {
if (success) {
// make arrays out of each of the passed strings
var nr:Array = lv.nr.split(",");
//var color:Array = this.color.split(",");
for (var i:Number=0; i < nr.length; i++) {
nrSum +=Number(nr[i]);
lv.push({
nr:Number(nr[i])
//colorarseInt(color[i], 16)
})
}
}
var height:Array = new Array();
for (var i:Number = 0; i < 10; i++) {
height[i] = (i + 5) ;
}
for (j=0; j < nr.length; j++) {
//draw column
r.beginFill(color[Number(Math.floor(Math.random()*len))], 50);
//r.beginGradientFill(fillType, colors, alphas, ratios, matrix);
r.lineStyle(1, 0xffffff, 100);
r.moveTo(xinit+j*45, 400);
r.lineTo(x1+j*45, 400);
r.lineTo(x1+j*45, 400-Number(nr[j]) * 20);
r.lineTo(xinit+j*45, 400-Number(nr[j]) * 20);
r.endFill();
//trace("nr"+" "+j+" "+Number(nr[j]));
//r.createTextField("moreinfo"+j, this.getNextHighestDepth(), xinit+j*30, Number(nr[j])*20-20, 10, 10);
//tFormat.color = 0x000000;
//this["moreinfo"+j].setNewTextFormat(tFormat);
//this["moreinfo"+j].text=nr[j];
}
for (i=1; i<=10; i++) {
createTextField("moreinfo" + i, this.getNextHighestDepth(), (i*30), (height*20 -20), 40, 30);
tFormat.color = 0x00ff00;
this["moreinfo" + i].setNewTextFormat(tFormat);
this["moreinfo" + i].text=20+i*30;
trace(20+i*30);
}
}
lv.load("textfiles/piechartsampledata_1.txt");
valori vengono presi da un file di testo che contiene questa stringa
&nr=1,2,3,4,5,6,7,8,9,10,9,8,7,6,5,4,3,2,1&
dove sta l'errore???

arseInt(color[i], 16)
Rispondi quotando
