To register for an Internet.com membership to receive newsletters and white papers, use the Register button ABOVE.
To participate in the message forums BELOW, click here


A Flash Developer Resource Site

Go Back   Flash Kit Community Forums > Flash Help > Flash ActionScript

Reply
 
Thread Tools Search this Thread Display Modes
Old 10-12-2004, 12:01 PM   #1
macbef
Member
 
Join Date: Sep 2002
Posts: 38
draw primitive with actionscript

i'm trying to make a loaderbar that's roud... so now i have done something with keyframes, but it makes the loader so big that it needs to be loaded itself anyone an idea on how to draw a circel (only a rounded line...) with some kind of script?!
i hope i'm clear enough...


i've attached an example of what i want, and how i've done it...
Attached Files
File Type: fla circeltje.fla (47.0 KB, 717 views)
macbef is offline   Reply With Quote
Old 10-12-2004, 01:47 PM   #2
jbum
Senior Member
 
jbum's Avatar
 
Join Date: Feb 2004
Location: Los Angeles
Posts: 2,920
code:


kRadiansToDegrees = 180/Math.PI;
kDegreesToRadians = Math.PI/180;

MovieClip.prototype.drawCircle = function(x,y,radius)
{
var r = radius;

var theta = 45*kDegreesToRadians;
var cr = radius/Math.cos(theta/2);
var angle = 0;
var cangle = -theta/2;

this.moveTo(x+r, y);
for (var i=0;i < 8;i++)
{
angle += theta;
cangle += theta;
var endX = r*Math.cos (angle);
var endY = r*Math.sin (angle);
var cX = cr*Math.cos (cangle);
var cY = cr*Math.sin (cangle);
this.curveTo(x+cX,y+cY, x+endX,y+endY);
}
}

_root.clear();
_root.lineStyle(1,0xFF0000,100);
_root.drawCircle(100,100,50);


__________________
jbum is offline   Reply With Quote
Old 10-13-2004, 01:03 PM   #3
macbef
Member
 
Join Date: Sep 2002
Posts: 38
really thanks man!
macbef is offline   Reply With Quote
Old 10-13-2004, 03:40 PM   #4
macbef
Member
 
Join Date: Sep 2002
Posts: 38
ok one more question... i've turned it into the loader i wanted, and i'm really pleased with the effect, but the only thing is that it slows down when the flash movie is further loaded.. now i think that's because i've placed the "for" loop in an "onEnterFrame", because i thought that was the only way the loader can be updated.. but is there an other way?!
Attached Files
File Type: fla loaderclip2.fla (160.0 KB, 375 views)
macbef is offline   Reply With Quote
Old 10-13-2004, 03:58 PM   #5
jbum
Senior Member
 
jbum's Avatar
 
Join Date: Feb 2004
Location: Los Angeles
Posts: 2,920
yeah, get rid of the onEnterFrame stuff you put inside drawcircle.

Instead, redraw the circle everytime you want to change theta, like so:

theta = laadHoek * kDegreesToRadians;
_root.clear();
_root.lineStyle(5, 0x9D9D9D, 100);
_root.drawCircle(20, 20, 15);


Secondly, I'm not sure why you're animating theta. If you want to change the size of the circle, you should animate the radius (the 15 you are passing in), and leave theta at 45*kDegreesToRadians. In this case, you would use something like:


theta = 45*kDegreesToRadians;
rad = kMinimumRadius + kMaximumRadius*percentloaded/100;
_root.clear();
_root.lineStyle(5, 0x9D9D9D, 100);
_root.drawCircle(20, 20, rad);
__________________
jbum is offline   Reply With Quote
Old 10-13-2004, 04:13 PM   #6
macbef
Member
 
Join Date: Sep 2002
Posts: 38
i don't get it, if i change the radius the circle gets smaller or bigger, so it's not like a line that goes round (like i want) so that's why i used theta...
macbef is offline   Reply With Quote
Old 10-13-2004, 04:18 PM   #7
jbum
Senior Member
 
jbum's Avatar
 
Join Date: Feb 2004
Location: Los Angeles
Posts: 2,920
Ah, you need something different, then what I imagined.

Do you want a line that emanates from the center of the circle (like a radar display)

or do you want a curved line that travels around the edge of the circle?

The first one is easy to do, and is not nearly as complicated as drawing a circle.

I have a different routine for doing the second (it's a variant of drawcircle that accepts a start-angle and end-angle) - you still need to keep theta at 45 degrees.
__________________
jbum is offline   Reply With Quote
Old 10-13-2004, 04:22 PM   #8
jbum
Senior Member
 
jbum's Avatar
 
Join Date: Feb 2004
Location: Los Angeles
Posts: 2,920
Here's the general purpose arc drawing routine. It accepts two additional arguments, bA (begin angle) and eA (end angle), both of which are expressed in degrees (0-360).

code:

degToRad = Math.PI/180;

MovieClip.prototype.drawArc = function(x,y,radius, bA,eA)
{
if (eA < bA) eA += 360;
var r = radius;

var n= Math.ceil((eA-bA)/45);

var theta = ((eA-bA)/n)*degToRad;
var cr = radius/Math.cos(theta/2);
var angle = bA*degToRad;
var cangle = angle-theta/2;

this.moveTo(x+r*Math.cos(angle), y+r*Math.sin(angle));
for (var i=0;i < n;i++)
{
angle += theta;
cangle += theta;
var endX = r*Math.cos (angle);
var endY = r*Math.sin (angle);
var cX = cr*Math.cos (cangle);
var cY = cr*Math.sin (cangle);
this.curveTo(x+cX,y+cY, x+endX,y+endY);
}
}



This is a modified version of the routine I used to make this:

http://krazydad.com/bestiary/bestiary_piechart.html
__________________
jbum is offline   Reply With Quote
Old 10-13-2004, 06:18 PM   #9
macbef
Member
 
Join Date: Sep 2002
Posts: 38
hmm i think i can use that as well... i'll try tomorrow if i can make it work with my idea! thanks for helping me so far!
macbef is offline   Reply With Quote
Reply

Go Back   Flash Kit Community Forums > Flash Help > Flash ActionScript

Thread Tools Search this Thread
Search this Thread:

Advanced Search
Display Modes

Posting Rules
You may not post new threads
You may not post replies
You may not post attachments
You may not edit your posts

BB code is On
Smilies are On
[IMG] code is On
HTML code is Off

Forum Jump


All times are GMT -4. The time now is 10:56 PM.


internet.commerce
Be a Commerce Partner
 »  »  »  »  »  »  »
 »  »  »  »  »  »
 

    

Acceptable Use Policy

internet.comMediabistrojusttechjobs.comGraphics.com

WebMediaBrands Corporate Info


Advertise | Newsletters | Feedback | Submit News

Legal Notices | Licensing | Permissions | Privacy Policy


Powered by vBulletin® Version 3.8.1
Copyright ©2000 - 2009, Jelsoft Enterprises Ltd.