Loading ring in flash

[ 2006-09-20 08:43:25 | Author: liuhuan ]
Font Size: Large | Medium | Small
Paste these codes in the first frame .
Source files : Click Here To Download
Quote
function drawRing(target_mc, instance, r1, r2, rgb, doHide) {
  var TO_RADIANS = 0.017453;
  target_mc[instance] == undefined ? (target_mc.createEmptyMovieClip(instance, target_mc.getNextHighestDepth())) : (target_mc[instance].clear());
  with (target_mc[instance]) {
    beginFill(rgb, 100);
    moveTo(0, 0);
    lineTo(r1, 0);
    var a = 0.268000;
    var i = 0;
    while (i<12) {
      var endx = r1*Math.cos((i+1)*30*TO_RADIANS);
      var endy = r1*Math.sin((i+1)*30*TO_RADIANS);
      var ax = endx+r1*a*Math.cos(((i+1)*30-90)*TO_RADIANS);
      var ay = endy+r1*a*Math.sin(((i+1)*30-90)*TO_RADIANS);
      curveTo(ax, ay, endx, endy);
      i++;
    }
    moveTo(0, 0);
    lineTo(r2, 0);
    var i = 12;
    while (i>0) {
      var endx = r2*Math.cos((i-1)*30*TO_RADIANS);
      var endy = r2*Math.sin((i-1)*30*TO_RADIANS);
      var ax = endx+r2*-a*Math.cos(((i-1)*30-90)*TO_RADIANS);
      var ay = endy+r2*-a*Math.sin(((i-1)*30-90)*TO_RADIANS);
      curveTo(ax, ay, endx, endy);
      i--;
    }
    endFill();
  }
  if (doHide) {
    target_mc[instance]._visible = false;
  }
  return (target_mc[instance]);
}
function drawSegment(target_mc, instance, x, y, radius, arc, startAngle, rgb) {
  var segAngle;
  var theta;
  var angle;
  var angleMid;
  var segs;
  var ax;
  var ay;
  var bx;
  var by;
  var cx;
  var cy;
  arc = -arc;
  if (Math.abs(arc)>360) {
    arc = 360;
  }
  segs = Math.ceil(Math.abs(arc)/45);
  segAngle = arc/segs;
  theta = -segAngle/180*3.141593;
  angle = -startAngle/180*3.141593;
  ax = x-Math.cos(angle)*radius;
  ay = y-Math.sin(angle)*radius;
  target_mc[instance] == undefined ? (target_mc.createEmptyMovieClip(instance, target_mc.getNextHighestDepth())) : (target_mc[instance].clear());
  with (target_mc[instance]) {
    beginFill(rgb, 100);
    moveTo(0, 0);
    lineTo(radius, 0);
    var i = 0;
    while (i<segs) {
      angle = angle+theta;
      angleMid = angle-theta/2;
      bx = ax+Math.cos(angle)*radius;
      by = ay+Math.sin(angle)*radius;
      cx = ax+Math.cos(angleMid)*(radius/Math.cos(theta/2));
      cy = ay+Math.sin(angleMid)*(radius/Math.cos(theta/2));
      curveTo(cx, cy, bx, by);
      i++;
    }
  }
  return (target_mc[instance]);
}
function loadingprocess() {
  var _Total;
  var _Loaded;
  var _Percent;
  _Total = getBytesTotal();
  _Loaded = getBytesLoaded();
  _Percent = _Loaded/_Total;
  var _angleease = 360*_Percent-angle;
  angle = angle+_angleease*ease;
  drawSegment(mc_loader, "bar", radius+5, 0, radius+5, angle, 0, 0xCCCCCC);
  drawRing(mc_loader, "mask", radius, radius-radius_diff, 0x0000FF);
  mc_loader.bar.setMask(mc_loader.mask);
  mc_loader._rotation = -90;
  if (_Total == _Loaded) {
    angle = 360;
    drawSegment(mc_loader, "bar", radius+5, 0, radius+5, angle, 0, 0xCCCCCC);
    drawRing(mc_loader, "mask", radius, radius-radius_diff, 0x0000FF);
    clearInterval(LoadingProcessInterval);
    die();
  }
}
function die() {
  Stage.removeListener(stageListener);
  mc_loader.removeMovieClip();
  gotoAndStop(2);
}
_global.reArrangeThings = function() {
  mc_loader._x = Stage.width/2;
  mc_loader._y = Stage.height/2;
};
this.onResize = function() {
  reArrangeThings();
};
getURL("FSCommand:allowscale", false);
getURL("FSCommand:fullscreen", true);
getURL("FSCommand:showmenu", false);
var mc_loader:MovieClip = this.createEmptyMovieClip("mc_loader", this.getNextHighestDepth());
reArrangeThings();
var radius = 40;
var radius_diff = 5;
var ease = 0.300000;
var angle = 0;
Stage.align = "TL";
_quality = "best";
System.useCodepage = false;
var LoadingProcessInterval = setInterval(_root, "loadingprocess", 1);
stop();
Stage.addListener(this);
[Last Modified By liuhuan, at 2006-09-20 09:05:39]
Comments Feed Comments Feed: http://www.liuhuan.com/blog/feed.asp?q=comment&id=623

There is no comment on this article.

You can't post comment on this article.