Flash Database Step By Step Tutorial - Part 10: Now, right click on third frame. Choose action. Enter following code:
// build chart
bar._visible = true;
question.text = myVar.title;
a = 1;
var jumlah:Number = 0;
while(myVar['choice' + a] != undefined){
jumlah = jumlah + parseInt(myVar['votes' + a]);
a++;
}
a = 1
while(myVar['choice' + a] != undefined){
duplicateMovieClip(answer, 'answer' + a, a);
duplicateMovieClip(bar, 'bar' + a, a + 300);
duplicateMovieClip(persen, 'persen' + a, a + 400);
duplicateMovieClip(lpersen, 'lpersen' + a, a + 500)
var value = myVar['votes' + a];
var label = myVar['choice' + a];
this['answer' + a]._y = _root.answer._y + (this['answer' + a]._height * (a - 1));
this['persen' + a]._y = this['answer' + a]._y;
this['bar' + a]._y = this['answer' + a]._y;
this['lpersen' + a]._y = this['answer' + a]._y;
this['answer' + a].text = label;
this['persen' + a].text = Math.round((parseInt(value)/jumlah) * 100);
this['bar' + a]._width = (parseInt(value)/jumlah) * 100;
a++;
}
bar._visible = false;
stop();
Now, test it! When you click result button, You may get like this:
