punstc
04-19-2009, 10:03 PM
I've been trying to make a circular preloader like you see all over the web but can't find any good info on how to actually do it. I can get it draw a circle fine in an enterframe but using the percent from a loader I can't get it to work properly.
heres what I have
var l:Loader = new Loader();
var mc:MovieClip = new MovieClip();
var xpos:Number = 0;
var ypos:Number = 0;
var angle:Number = 0;
var speed:Number = .05;
var radius:Number = 50;
l.contentLoaderInfo.addEventListener(ProgressEvent.PROGRESS, onProgress)
l.contentLoaderInfo.addEventListener(Event.COMPLETE, onComplete)
l.load(new URLRequest("large.swf"));
mc.graphics.moveTo(stage.stageWidth/2,stage.stageHeight/2);
mc.graphics.beginFill(0x00ff00);
addChild(mc);
function onProgress(e:ProgressEvent):void
{
var perc = (e.bytesLoaded / e.bytesTotal) * 100;
xpos = stage.stageWidth/2 + Math.cos(angle) * radius;
ypos = stage.stageHeight/2 + Math.sin(angle) * radius;
angle = (perc*radius)/360;
trace(angle)
mc.graphics.lineTo (xpos,ypos);
}
function onComplete(e:Event)
{
addChildAt(l,0);
//removeChild(mc);
}
right now it goes around about 3 and a quarter times, and based of the speed of the download the circle becomes less smooth.
I have a demo of what i got now at:
http://www.jchamb.com/files/circlepreloader/preload.swf
the fla is there too.
I've really just started messing around with the graphics and math classes in flash and don't really know what I'm doing. Any help would be appreciated.
heres what I have
var l:Loader = new Loader();
var mc:MovieClip = new MovieClip();
var xpos:Number = 0;
var ypos:Number = 0;
var angle:Number = 0;
var speed:Number = .05;
var radius:Number = 50;
l.contentLoaderInfo.addEventListener(ProgressEvent.PROGRESS, onProgress)
l.contentLoaderInfo.addEventListener(Event.COMPLETE, onComplete)
l.load(new URLRequest("large.swf"));
mc.graphics.moveTo(stage.stageWidth/2,stage.stageHeight/2);
mc.graphics.beginFill(0x00ff00);
addChild(mc);
function onProgress(e:ProgressEvent):void
{
var perc = (e.bytesLoaded / e.bytesTotal) * 100;
xpos = stage.stageWidth/2 + Math.cos(angle) * radius;
ypos = stage.stageHeight/2 + Math.sin(angle) * radius;
angle = (perc*radius)/360;
trace(angle)
mc.graphics.lineTo (xpos,ypos);
}
function onComplete(e:Event)
{
addChildAt(l,0);
//removeChild(mc);
}
right now it goes around about 3 and a quarter times, and based of the speed of the download the circle becomes less smooth.
I have a demo of what i got now at:
http://www.jchamb.com/files/circlepreloader/preload.swf
the fla is there too.
I've really just started messing around with the graphics and math classes in flash and don't really know what I'm doing. Any help would be appreciated.