|
发表于 22-3-2006 05:54 AM
|
显示全部楼层
MovieClip.prototype.createTextArea = function(x:Number, y:Number, lbl:String, txt:Number, depth:Number) {
var mc:MovieClip = this.createEmptyMovieClip("textArea"+depth, depth);
mc._x = x;
mc._y = y;
mc.createTextField("label", 0, 0, 0, 0, 0);
mc.label.text = lbl;
mc.label.autoSize = true;
mc.createTextField("txt", 1, mc.label._width+5, 0, 50, 20);
mc.txt.text = txt;
mc.txt.type = "input";
mc.txt.border = true;
mc.txt.onChanged = function(target:TextField) {
this._parent._parent.init();
};
}
MovieClip.prototype.drawBar = function(x:Number, y:Number, w:Number, h:Number, c:Number) {
var depth:Number = this.getNextHighestDepth();
var mc:MovieClip = this.createEmptyMovieClip("bar"+depth, depth);
with(mc) {
lineStyle(1);
beginFill(c);
moveTo(x, y);
lineTo(x, y-h);
lineTo(x+w, y-h);
lineTo(x+w, y);
endFill();
}
}
getTotal = function() {
var totalHeight:Number = 0;
for(var i=0; i<barInit; i++) {
totalHeight += int(this["textArea"+i].txt.text);
}
return totalHeight;
}
init = function() {
var barChart:MovieClip = this.createEmptyMovieClip("barChart", 100);
barChart._x = graphPos[0];
barChart._y = graphPos[1];
for(var i=0; i<barInit; i++) {
var rate:Number = this["textArea"+i].txt.text / getTotal();
var h:Number = rate * graphHeight;
barChart.drawBar((i * 30), 0, 20, h, 0xFF99CC);
}
}
var barInit:Number = 3;
var labelPos:Array = new Array(50, 20);
var graphPos:Array = new Array(50, 300);
var graphHeight:Number = 200;
for(var i:Number=0; i<barInit; i++) {
var rand:Number = Math.round(Math.random(300)*1000);
this.createTextArea(labelPos[0], (i * 30)+labelPos[1], 'Bar'+(i+1)+' : ', rand, i);
}
init();
沒什麽時間,隨便寫了個例子。自己參考init中的計算吧...
打開一個新文件,把以上代碼貼在第一个frame就可以了 |
|