package
{
import flash.display.Graphics;1076837207.as
import flash.display.Sprite;
import flash.events.*;
/**
* …
* @author …
*/
public class PreLoader extends Sprite
{
var circleToMask:Sprite = new Sprite();
var circle:Sprite = new Sprite();
var circleMask:Sprite = new Sprite();
var percentage:Number = 0;
var tper:Number = 0;
var i:Number = 0;
public function PreLoader(x:Number,y:Number)
{
//큰원을 그린다.
circleToMask.graphics.beginFill(16755370);
circleToMask.graphics.drawCircle(0, 0, 10);
circleToMask.graphics.endFill();
addChild(circleToMask);
//그속에 하얀색 원을 작게 하나 그린다.
circle.graphics.beginFill(0xffffff);
circle.graphics.drawCircle(0, 0, 7);
circle.graphics.endFill();
//그리고 큰원에 마스크를 준다.
addChild(circleToMask);
addChild(circle);
addChild(circleMask);
circle.x = x;//(circle.x = x);
circle.y = y;//(circle.y = y);
circleToMask.x = (circleMask.x = x);
circleToMask.y = (circleMask.y = y);
circleToMask.mask = circleMask;
addEventListener(Event.ENTER_FRAME, function (_arg1:Event):void{
if(i >=100) i=0;
i++;
circleMask.rotation = (i/20)/(Math.PI/180)
trace(circleToMask.rotation);
})
}
public function SetStep(percentage:Number):void
{
graphics.clear();
// Percentage should be between 0 and 1
tper = percentage < 0 ? 0 : (percentage > 1 ? 1 : percentage);
// Draw the masked circle
circleMask.graphics.clear();
circleMask.graphics.beginFill(0);
drawPieMask(circleMask.graphics, tper, 10, 0, 0, (-(Math.PI) / 2), 3);
circleMask.graphics.endFill();
// Increase percentage with margins so it appears to stop for a short while
percentage = (percentage + 0.01);
if (percentage > 1.05){
percentage = -0.05;
}
}
public function drawPieMask(graphics:Graphics, percentage:Number, radius:Number = 10, x:Number = 0, y:Number = 0, rotation:Number = 0, sides:int = 6):void {
// graphics should have its beginFill function already called by now
graphics.moveTo(x, y);
if (sides < 3) sides = 3; // 3 sides minimum
// Increase the length of the radius to cover the whole target
radius /= Math.cos(1/sides * Math.PI);
// Shortcut function
var lineToRadians:Function = function(rads:Number):void {
graphics.lineTo(Math.cos(rads) * radius + x, Math.sin(rads) * radius + y);
};
// Find how many sides we have to draw
var sidesToDraw:int = Math.floor(percentage * sides);
for (var i:int = 0; i <= sidesToDraw; i++)
lineToRadians((i / sides) * (Math.PI * 2) + rotation);
// Draw the last fractioned side
if (percentage * sides != sidesToDraw)
lineToRadians(percentage * (Math.PI * 2) + rotation);
}
}
}