code_intro

代码
  1. 下面示例中的
  2. DrawSector(moviec,200,200,100,S_angle,270,0xffcc00);
  3. 函数就是画扇形的函数,
  4. moviec是扇形所在影片剪辑的名字
  5. 第2,3个参数是扇形原点的横纵坐标
  6. 第4个参数是扇形的半径
  7. 第5个参数S_angle是扇形的角度
  8. 第6个参数是扇形的起始角度
  9. 第7个参数0xffcc00是扇形的颜色
  10. /*
  11. *Create by Geordi 14th Feb 2008
  12. *function DrawSector is drawing a sector in the flash by
  13. actionscript 3
  14. */
  15. import flash.display.MovieClip;
  16. import flash.display.Sprite;
  17. var stag:Sprite=new Sprite();
  18. addChild(stag);
  19. var moviec:MovieClip=new MovieClip;
  20. stag.addChild(moviec);
  21. var S_angle:int=60;
  22. /* S_angle is expressed as a number between 0 and 360 degrees. it
  23. will draw a 60
  24. * degree sector in this example, but you could change it to what
  25. ever you want
  26. */
  27. DrawSector(moviec,200,200,100,S_angle,270,0xffcc00);
  28. /*
  29. * mc the movieclip: the container of the sector.
  30. * x,y the center position of the sector
  31. * r the radius of the sector
  32. * angle the angle of the sector
  33. * startFrom the start degree counting point : 270 top, 180 left, 0
  34. right, 90 bottom ,
  35. * it is counting from top in this example.
  36. * color the fil lin color of the sector
  37. */
  38. function
  39. DrawSector(mc:MovieClip,x:Number=200,y:Number=200,r:Number=100,angle
  40. :Number=27,startFrom:Number=270,color:Number=0xff0000):void {
  41.   mc.graphics.beginFill(color,50);
  42.  //remove this line to unfill the sector
  43.  /* the border of the secetor with color 0xff0000 (red) , you
  44. could replace it with any color
  45.   * you want like 0x00ff00(green) or 0x0000ff (blue).
  46.  */
  47.   mc.graphics.lineStyle(0,0xff0000);
  48.   mc.graphics.moveTo(x,y);
  49.   angle=(Math.abs(angle)>360)?360:angle;
  50.  var n:Number=Math.ceil(Math.abs(angle)/45);
  51.  var angleA:Number=angle/n;
  52.   angleA=angleA*Math.PI/180;
  53.   startFrom=startFrom*Math.PI/180;
  54. mc.graphics.lineTo(x+r*Math.cos(startFrom),y+r*Math.sin(startFrom));
  55.  for (var i=1; i<=n; i++) {
  56.    startFrom+=angleA;
  57.   var angleMid=startFrom-angleA/2;
  58.   var bx=x+r/Math.cos(angleA/2)*Math.cos(angleMid);
  59.   var by=y+r/Math.cos(angleA/2)*Math.sin(angleMid);
  60.   var cx=x+r*Math.cos(startFrom);
  61.   var cy=y+r*Math.sin(startFrom);
  62.    mc.graphics.curveTo(bx,by,cx,cy);
  63.   }
  64.  if (angle!=360) {
  65.    mc.graphics.lineTo(x,y);
  66.   }
  67.   mc.graphics.endFill();// if you want a sector without filling
  68. color , please remove this line.
  69. }