flash纯动态生成饼图第2/2页
更新时间:2007年03月15日 00:00:00 作者:
所有代码放到影片的时间轴上的一帧中就可以了。
复制代码 代码如下:
/*
mc为影片名。
x0,y0圆心坐标;w1,w2为长短轴;a0为开始度数,a为结束度数,h为高, hw为环宽,color为十六进制颜色,
movew为移动距离,alpha为透明度(点击之后),mcalpha为原始透明度,movenow为确定默认载入时是否移动出去,
valuepercent为百分比值,arr_name为每项名称,arr_showname确定是否显示名称与值,
titleline显示名称与值的长短位置,linecolor指示线颜色,linealpha指示线透明度,fontcolor文字颜色,percentshow是否显示百分比值,dark深色系数(>1如1.43)
本pie对应竖向排列方块mc名。
*/
function drawCircle(mc:MovieClip,
x0:Number, y0:Number, w1:Number, w2:Number, a0:Number, a:Number, h:Number, hw:Number, color:Number,
movew:Number, alpha:Number, mcalpha:Number, movenow:String,
valuepercent:Number, arr_name:String, arr_showname:String,
titleline:Number, linecolor:Number,linealpha:Number, fontcolor:Number,percentshow:String,dark:Number,
ordermc:MovieClip):Void {
//加减间隔度
step = 1;
//求内长短轴
leichang = w1-hw;
leiduan = w2-(hw*w2/w1);
//深色
hicolor = darkcolor(color,dark);
//---------------------------------
//下面为下面环;
mc.beginFill(color, 100);
//mc.lineStyle(1, color, 100, false, "none");
//外边
mc.moveTo(getPoint(x0, y0+h, w1, w2, a0).x, getPoint(x0, y0+h, w1, w2, a0).y);
k = a0;
while (k<a) {
k += step;
mc.lineTo(getPoint(x0, y0+h, w1, w2, k).x, getPoint(x0, y0+h, w1, w2, k).y);
}
//侧边1
mc.lineTo(getPoint(x0, y0+h, leichang, leiduan, k).x, getPoint(x0, y0+h, leichang, leiduan, k).y);
//内边
while (k>a0) {
k -= step;
mc.lineTo(getPoint(x0, y0+h, leichang, leiduan, k).x, getPoint(x0, y0+h, leichang, leiduan, k).y);
}
//侧边2
mc.lineTo(getPoint(x0, y0+h, leichang, leiduan, a0).x, getPoint(x0, y0+h, leichang, leiduan, a0).y);
mc.endFill();
//--------------------------------
//下边高
//下边外侧边高
if(a0<=0 && a>=0 && a<=180){
//解决90度时外侧面,显示事实为90度,实际为0度,因为我们整个旋转了-90度;
mc.beginFill(hicolor, 100);
mc.moveTo(getPoint(x0, y0+h, w1, w2, a0).x, getPoint(x0, y0+h, w1, w2, a0).y);
k=a0;
while (k<0) {
k += step;
mc.lineTo(getPoint(x0, y0+h, w1, w2, k).x, getPoint(x0, y0+h, w1, w2, k).y);
}
mc.lineTo(getPoint(x0, y0, w1, w2, 0).x, getPoint(x0, y0, w1, w2, 0).y);
while (k>a0){
k -=step;
mc.lineTo(getPoint(x0, y0, w1, w2, k).x, getPoint(x0, y0, w1, w2, k).y);
}
mc.endFill();
mc.beginFill(hicolor, 100);
mc.moveTo(getPoint(x0, y0+h, w1, w2, 0).x, getPoint(x0, y0+h, w1, w2, 0).y);
k=0;
while (k<a) {
k += step;
mc.lineTo(getPoint(x0, y0+h, w1, w2, k).x, getPoint(x0, y0+h, w1, w2, k).y);
}
mc.lineTo(getPoint(x0, y0, w1, w2, a).x, getPoint(x0, y0, w1, w2, a).y);
while (k>0){
k -=step;
mc.lineTo(getPoint(x0, y0, w1, w2, k).x, getPoint(x0, y0, w1, w2, k).y);
}
mc.endFill();
}else if(a>=180 && a0<=180 && a0>=0){
//解决180度时外侧面,显示事实为270度,实际为180度,因为我们整个旋转了-90度;
mc.beginFill(hicolor, 100);
mc.moveTo(getPoint(x0, y0+h, w1, w2, a0).x, getPoint(x0, y0+h, w1, w2, a0).y);
k=a0;
while (k<180) {
k += step;
mc.lineTo(getPoint(x0, y0+h, w1, w2, k).x, getPoint(x0, y0+h, w1, w2, k).y);
}
mc.lineTo(getPoint(x0, y0, w1, w2, 180).x, getPoint(x0, y0, w1, w2, 180).y);
while (k>a0){
k -=step;
mc.lineTo(getPoint(x0, y0, w1, w2, k).x, getPoint(x0, y0, w1, w2, k).y);
}
mc.endFill();
mc.beginFill(hicolor, 100);
mc.moveTo(getPoint(x0, y0+h, w1, w2, 180).x, getPoint(x0, y0+h, w1, w2, 180).y);
k=180;
while (k<a) {
k += step;
mc.lineTo(getPoint(x0, y0+h, w1, w2, k).x, getPoint(x0, y0+h, w1, w2, k).y);
}
mc.lineTo(getPoint(x0, y0, w1, w2, a).x, getPoint(x0, y0, w1, w2, a).y);
while (k>180){
k -=step;
mc.lineTo(getPoint(x0, y0, w1, w2, k).x, getPoint(x0, y0, w1, w2, k).y);
}
mc.endFill();
}else if(a0<=0 && a>=180){
//解决同时处于0度和180度的情况
mc.beginFill(hicolor, 100);
mc.moveTo(getPoint(x0, y0+h, w1, w2, a0).x, getPoint(x0, y0+h, w1, w2, a0).y);
k=a0;
while (k<0) {
k += step;
mc.lineTo(getPoint(x0, y0+h, w1, w2, k).x, getPoint(x0, y0+h, w1, w2, k).y);
}
mc.lineTo(getPoint(x0, y0, w1, w2, 0).x, getPoint(x0, y0, w1, w2, 0).y);
while (k>a0){
k -=step;
mc.lineTo(getPoint(x0, y0, w1, w2, k).x, getPoint(x0, y0, w1, w2, k).y);
}
mc.endFill();
mc.beginFill(hicolor, 100);
mc.moveTo(getPoint(x0, y0+h, w1, w2, 0).x, getPoint(x0, y0+h, w1, w2, 0).y);
k=0;
while (k<180) {
k += step;
mc.lineTo(getPoint(x0, y0+h, w1, w2, k).x, getPoint(x0, y0+h, w1, w2, k).y);
}
mc.lineTo(getPoint(x0, y0, w1, w2, 180).x, getPoint(x0, y0, w1, w2, 180).y);
while (k>0){
k -=step;
mc.lineTo(getPoint(x0, y0, w1, w2, k).x, getPoint(x0, y0, w1, w2, k).y);
}
mc.endFill();
mc.beginFill(hicolor, 100);
mc.moveTo(getPoint(x0, y0+h, w1, w2, 180).x, getPoint(x0, y0+h, w1, w2, 180).y);
k=180;
while (k<a) {
k += step;
mc.lineTo(getPoint(x0, y0+h, w1, w2, k).x, getPoint(x0, y0+h, w1, w2, k).y);
}
mc.lineTo(getPoint(x0, y0, w1, w2, a).x, getPoint(x0, y0, w1, w2, a).y);
while (k>180){
k -=step;
mc.lineTo(getPoint(x0, y0, w1, w2, k).x, getPoint(x0, y0, w1, w2, k).y);
}
mc.endFill();
}else{
mc.beginFill(hicolor, 100);
mc.moveTo(getPoint(x0, y0+h, w1, w2, a0).x, getPoint(x0, y0+h, w1, w2, a0).y);
k = a0;
while (k<a) {
k += step;
mc.lineTo(getPoint(x0, y0+h, w1, w2, k).x, getPoint(x0, y0+h, w1, w2, k).y);
}
//mc.lineTo(getPoint(x0, y0+h, w1, w2, a).x, getPoint(x0, y0+h, w1, w2, a).y);
mc.lineTo(getPoint(x0, y0, w1, w2, k).x, getPoint(x0, y0, w1, w2, k).y);
while (k>a0) {
k -= step;
mc.lineTo(getPoint(x0, y0, w1, w2, k).x, getPoint(x0, y0, w1, w2, k).y);
}
mc.endFill();
}
//下边开始侧面高
mc.beginFill(hicolor, 100);
//mc.lineStyle(1, hicolor, 100, false, "none");
mc.moveTo(getPoint(x0, y0+h, w1, w2, a0).x, getPoint(x0, y0+h, w1, w2, a0).y);
mc.lineTo(getPoint(x0, y0+h, leichang, leiduan, a0).x, getPoint(x0, y0+h, leichang, leiduan, a0).y);
mc.lineTo(getPoint(x0, y0, leichang, leiduan, a0).x, getPoint(x0, y0, leichang, leiduan, a0).y);
mc.lineTo(getPoint(x0, y0, w1, w2, a0).x, getPoint(x0, y0, w1, w2, a0).y);
mc.endFill();
//下面结束侧面高
mc.beginFill(hicolor, 100);
//mc.lineStyle(1, hicolor, 100, false, "none");
mc.moveTo(getPoint(x0, y0+h, w1, w2, a).x, getPoint(x0, y0+h, w1, w2, a).y);
mc.lineTo(getPoint(x0, y0+h, leichang, leiduan, a).x, getPoint(x0, y0+h, leichang, leiduan, a).y);
mc.lineTo(getPoint(x0, y0, leichang, leiduan, a).x, getPoint(x0, y0, leichang, leiduan, a).y);
mc.lineTo(getPoint(x0, y0, w1, w2, a).x, getPoint(x0, y0, w1, w2, a).y);
mc.endFill();
//下面内侧面高
mc.beginFill(hicolor, 100);
//mc.lineStyle(1, hicolor, 100, false, "none");
mc.moveTo(getPoint(x0, y0+h, leichang, leiduan, a0).x, getPoint(x0, y0+h, leichang, leiduan, a0).y);
k = a0;
while (k<a) {
k += step;
mc.lineTo(getPoint(x0, y0+h, leichang, leiduan, k).x, getPoint(x0, y0+h, leichang, leiduan, k).y);
}
mc.lineTo(getPoint(x0, y0, leichang, leiduan, k).x, getPoint(x0, y0, leichang, leiduan, k).y);
while (k>a0) {
k -= step;
mc.lineTo(getPoint(x0, y0, leichang, leiduan, k).x, getPoint(x0, y0, leichang, leiduan, k).y);
}
mc.endFill();
//---------------------------------
//下面为上面环;
mc.beginFill(color, 100);
//mc.lineStyle(1, color, 100, false, "none");
//外边
mc.moveTo(getPoint(x0, y0, w1, w2, a0).x, getPoint(x0, y0, w1, w2, a0).y);
k = a0;
while (k<a) {
k += step;
mc.lineTo(getPoint(x0, y0, w1, w2, k).x, getPoint(x0, y0, w1, w2, k).y);
}
//侧边1
mc.lineTo(getPoint(x0, y0, leichang, leiduan, k).x, getPoint(x0, y0, leichang, leiduan, k).y);
//内边
while (k>a0) {
k -= step;
mc.lineTo(getPoint(x0, y0, leichang, leiduan, k).x, getPoint(x0, y0, leichang, leiduan, k).y);
}
//侧边2
mc.lineTo(getPoint(x0, y0, leichang, leiduan, a0).x, getPoint(x0, y0, leichang, leiduan, a0).y);
mc.endFill();
//--------------------------------------显示名称与值
if(arr_showname=="true"){
mc.beginFill(color, 100);
mc.lineStyle(1, linecolor, linealpha);
mc.moveTo(getPoint(x0, y0, w1, w2, a0+(a-a0)/2).x,getPoint(x0, y0, w1, w2, a0+(a-a0)/2).y);
mc.lineTo(getPoint(x0, y0, w1+titleline, w2+(w2*titleline)/w1, a0+(a-a0)/2).x,getPoint(x0, y0, w1+titleline, w2+(w2*titleline)/w1, a0+(a-a0)/2).y);
mc.endFill();
//trace(mc._name+":"+(a0+(a-a0)/2));
if(a0+(a-a0)/2>0 && a0+(a-a0)/2<90){
var label:TextField = mc.createTextField("label", 1, getPoint(x0, y0, w1+titleline, w2+(w2*titleline)/w1, a0+(a-a0)/2).x, getPoint(x0, y0, w1+titleline, w2+(w2*titleline)/w1, a0+(a-a0)/2).y, 0, 0);
label.autoSize = "left";
}else if(a0+(a-a0)/2>90 && a0+(a-a0)/2<180){
var label:TextField = mc.createTextField("label", 1, getPoint(x0, y0, w1+titleline, w2+(w2*titleline)/w1, a0+(a-a0)/2).x, getPoint(x0, y0, w1+titleline, w2+(w2*titleline)/w1, a0+(a-a0)/2).y, 0, 0);
label.autoSize = "right";
}else if(a0+(a-a0)/2>180 && a0+(a-a0)/2<270){
var label:TextField = mc.createTextField("label", 1, getPoint(x0, y0, w1+titleline, w2+(w2*titleline)/w1, a0+(a-a0)/2).x, getPoint(x0, y0, w1+titleline, w2+(w2*titleline)/w1, a0+(a-a0)/2).y-18, 0, 0);
label.autoSize = "right";
}else if(a0+(a-a0)/2>-90 && a0+(a-a0)/2<0){
var label:TextField = mc.createTextField("label", 1, getPoint(x0, y0, w1+titleline, w2+(w2*titleline)/w1, a0+(a-a0)/2).x, getPoint(x0, y0, w1+titleline, w2+(w2*titleline)/w1, a0+(a-a0)/2).y-18, 0, 0);
label.autoSize = "left";
}else if(a0+(a-a0)/2==0){
var label:TextField = mc.createTextField("label", 1, getPoint(x0, y0, w1+titleline, w2+(w2*titleline)/w1, a0+(a-a0)/2).x, getPoint(x0, y0, w1+titleline, w2+(w2*titleline)/w1, a0+(a-a0)/2).y-9, 0, 0);
label.autoSize = "left";
}else if(a0+(a-a0)/2==90){
var label:TextField = mc.createTextField("label", 1, getPoint(x0, y0, w1+titleline, w2+(w2*titleline)/w1, a0+(a-a0)/2).x, getPoint(x0, y0, w1+titleline, w2+(w2*titleline)/w1, a0+(a-a0)/2).y, 0, 0);
label.autoSize = "center";
}else if(a0+(a-a0)/2==180){
var label:TextField = mc.createTextField("label", 1, getPoint(x0, y0, w1+titleline, w2+(w2*titleline)/w1, a0+(a-a0)/2).x, getPoint(x0, y0, w1+titleline, w2+(w2*titleline)/w1, a0+(a-a0)/2).y-9, 0, 0);
label.autoSize = "right";
}
label.html = true;
if(percentshow=="all"){
label.htmlText = arr_name+":"+valuepercent+"%";
}else if(percentshow=="font"){
label.htmlText = arr_name;
}else if(percentshow=="num"){
label.htmlText = valuepercent+"%";
}
var myformat:TextFormat = new TextFormat();
myformat.font = "Verdana";
myformat.size = 12;
myformat.color = fontcolor;
label.setTextFormat(myformat);
label.gridFitType = "pixel";
label.antiAliasType = "advanced";
label.sharpness = -400;
}
//--------------------------------------
//点击移动
mc.onRelease = function(){
//移动方向:度数:
go_a = a0+(a-a0)/2;
//移动距离
go_w = movew;
//trace(this._name);
//trace(this.enabled);
if(mc._x!=0 || mc._y!=0){
myTweeen3=new Tween(mc,"_x",Bounce.easeOut,mc._x,(mc._x - (getPoint(x0,y0,go_w,go_w,go_a).x-x0)),1.5,true);
myTweeen4=new Tween(mc,"_y",Bounce.easeOut,mc._y,(mc._x - (getPoint(x0,y0,go_w,go_w,go_a).x-x0)),1.5,true);
//透明度
myTweeenalpha2=new Tween(mc,"_alpha",Regular.easeOut,mc._alpha,mcalpha,1,true);
var listener3:Object = new Object();
mc.enabled = false;
ordermc.enabled = false;//竖向排列本pie对应的方块mc
listener3.onMotionFinished = function(){
mc.enabled = true;
ordermc.enabled = true;//竖向排列本pie对应的方块mc
}
myTweeen3.addListener(listener3);
//mc._x = mc._x - (getPoint(x0,y0,go_w,go_w,go_a).x-x0);
//mc._y = mc._y - (getPoint(x0,y0,go_w,go_w,go_a).y-y0);
}else{
//到达新点
myTweeen1=new Tween(mc,"_x",Regular.easeOut,mc._x,(getPoint(x0,y0,go_w,go_w,go_a).x-x0),1,true);
myTweeen2=new Tween(mc,"_y",Regular.easeOut,mc._y,(getPoint(x0,y0,go_w,go_w,go_a).y-y0),1,true);
//透明度
myTweeenalpha=new Tween(mc,"_alpha",Regular.easeOut,mc._alpha,alpha,1,true);
var listener1:Object = new Object();
mc.enabled = false;
ordermc.enabled = false;//竖向排列本pie对应的方块mc
listener1.onMotionFinished = function(){
mc.enabled = true;
ordermc.enabled = true;//竖向排列本pie对应的方块mc
}
myTweeen1.addListener(listener1);
}
//trace(this.getDepth());
}
//默认位置(移动)
if(movenow=="true"){
//移动方向:度数:
go_a = a0+(a-a0)/2;
//移动距离
go_w = movew;
myTweeen5=new Tween(mc,"_x",Regular.easeOut,mc._x,(getPoint(x0,y0,go_w,go_w,go_a).x-x0),1,true);
myTweeen6=new Tween(mc,"_y",Regular.easeOut,mc._y,(getPoint(x0,y0,go_w,go_w,go_a).y-y0),1,true);
//透明度
myTweeenalpha=new Tween(mc,"_alpha",Regular.easeOut,mc._alpha,alpha,1,true);
var listener5:Object = new Object();
mc.enabled = false;
ordermc.enabled = false;//竖向排列本pie对应的方块mc
listener5.onMotionFinished = function(){
mc.enabled = true;
ordermc.enabled = true;//竖向排列本pie对应的方块mc
}
myTweeen5.addListener(listener5);
}
}
/*--------------------------------------------------------------------------------------------
x=a*cosX //x、y是椭圆上一点的坐标;a、b分别是长、短轴
y=b*sinX //X是椭圆旋转的角度。
计算椭圆上点的位置函数,x0,y0为圆心;w,h为长短轴;a为度数。返回一个坐标对象,有x和y两个属性。
*/
function getPoint(x0:Number, y0:Number, w:Number, h:Number, a:Number):Object {
a = a*Math.PI/180;
return {x:Math.cos(a)*w+x0, y:Math.sin(a)*h+y0};
}
//--------------------------------------------------------------------------------------
/*--------------------------------------------------------------------------------------------
将颜色加深
原有颜色oldcolor为十六进表示法如:0xff6600;返回同样类型的值
*/
function darkcolor(oldcolor:Number,dark:Number):Number{
//求暗色
if(oldcolor.toString(16).length<6){//防止这个十六进制数的第一位为0;
r = parseInt("0x0"+substring(oldcolor.toString(16), 0, 1));
g = parseInt("0x"+substring(oldcolor.toString(16), 2, 2));
b = parseInt("0x"+substring(oldcolor.toString(16), 4, 2));
}else{
r = parseInt("0x"+substring(oldcolor.toString(16), 0, 2));
g = parseInt("0x"+substring(oldcolor.toString(16), 3, 2));
b = parseInt("0x"+substring(oldcolor.toString(16), 5, 2));
}
//trace("原始rgb:"+r+":"+g+":"+b);
//dark = 1.43;
r=Math.round(r/dark).toString(16);
g=Math.round(g/dark).toString(16);
b=Math.round(b/dark).toString(16);
//trace("新rgb:"+r+":"+g+":"+b);
r.length==1 ? r="0"+r:r;
g.length==1 ? g="0"+g:g;
b.length==1 ? b="0"+b:b;
var hicolor:Number;
hicolor = parseInt("0x"+r.toString(16)+""+g.toString(16)+""+b.toString(16));
r = parseInt("0x"+substring(hicolor.toString(16), 0, 2));
g = parseInt("0x"+substring(hicolor.toString(16), 3, 2));
b = parseInt("0x"+substring(hicolor.toString(16), 5, 2));
return hicolor;
}
本地下载this.alt='点击在新窗口查看全图\nCTRL+鼠标滚轮放大或缩小';}" border=0>
本地下载
相关文章
Flash两个上传示例ASP和PHP(原文件下载,包括后台程序)
Flash两个上传示例ASP和PHP(原文件下载,包括后台程序)...2006-11-11
最新评论