Tracking Forums, Newsgroups, Maling Lists
Home Scripts Tutorials Tracker Forums
  Advanced Search
  HOME    TRACKER    Flash




Circle Segment With Drawing Methods



How can I draw a circle segment (for example a quarter of a circle) using the drawing methods? I'm looking for a function which loops through a for-statement using a radius -parameter within the function. The radius is supposed to be altered with Event-handlers (e.g onEnterFrame).Thanks for any suggestions!!



ActionScript.org Forums > ActionScript Forums Group > ActionScript 2.0
Posted on: 05-18-2007, 10:37 AM


View Complete Forum Thread with Replies

See Related Forum Messages: Follow the Links Below to View Complete Thread

Line Segment / Circle Intersection Test?
Anyone know how to test if a line segment intersects a circle at anytime? I need to implement this as my 1 stage collision detection for my artificial life simulating boids...

[MATH] Figuring Control Points For 5 Segment Circle
i need a formula for figuring control points for a 5 segment circle where there is a point every 72degrees.

i've seen many examples for 8 segment circles but never 5.

Drawing A Animated Circle, Dot To Circle
Can some one help me??

Im new in Flash, I want to make an animation of a circle, begining from a small dot and ending in a circle (like wen we draw in a paper), I allready tried everything I know (not a lot!!!! ) .

Is it possible to make this? I will trie to explain:

I want to make a animation of a small pencil drawing a circle from nothing. Begining with the pencil drawing a dot then that pencil will make the complete circle like wen we draw in a paper by hand.

Sorry my English is not very good.

Please Help!

Arcanjo

Drawing Methods
I am trying to draw a shape at the level of a movieClip, but the code only works if I draw the line at the root level.
The movie clip is attached dynamicaly to the root, and draws the shape - only once- on enterFrame.

myMovieClip.prototype.onEnterFrame = function(){
if (!inited) {this.setHotSpot();}
}

myMovieClip.prototype.setHotSpot=function(){
this.createEmptyMovieClip( "hotSpot", 2 );
trace ("hotspot" + this.hotSpot)
with ( this.hotSpot )
{
lineStyle( 5, 0xffff00, 100 );
moveTo( 10, 10 );
lineTo( 10, 40 );
lineTo( 50, 50 );
lineTo( 50, 10 );
lineTo( 10, 10 );
}

the setHotSpot function doe not work unless I replace "this" with "_root".

Any help would be great.
Thanks
geraldine

[as 1.0 3d] 3d Flash Not Using The Drawing Methods
I'm trying to create a 3d mask effect in flash - and have run into some problems.

I've managed to create a complex 3d model within flash - using point objects and the lineTo/beginFill/endFill methods - and then using setMask to mask the clip. This all works fine - but this where the problem comes in.

The .swf is actually being decomplied and then recompiled using a c++ based scripting engine (enabling me to bring a 3d model from maya into the flash, replacing the masked clip). However this custom software doesn't fully implement all of the flash methods - so the drawing commands actually fail. The obvious solution is to implement them - but we haven't the time.

What I therefore need to do is create the 3d mask using scaled/skewed polygons.

(Also if I could extend this to show textured fills - I would be very happy)

Has anyone managed to do this? Any tips?

Cheers,

Nick

[F8] Full Width Using Drawing Methods
_root.lineStyle(1, 0x0000FF, 100);
_root.moveTo(-100,100);
_root.lineTo(1000, 100);

i'm using the above code to draw a line across the page.
Is there a way to link this to publish settings at 100% width of the page?


rat

Drawing Methods And Constraining With HitTest
Thanks to the samples and stuff on this board and other places online, I've got the beginnings of a nice little online app that will eventually be used to do measurements on medical images. This really isn't that relevant to the problem I've got though.

This has got to be simple, but I can't get it to work.

The file is structured as following:

-main stage has an MC into which a medical image is loaded from disk (just a jpeg)
-one layer above that is the "canvas" MC. This MC has two layers, a simple square border and the code to enable the straight line drawing methods. Because we are later going to do calculations on the lines, the drawing space needs to be in proper alignment (coordinates-wise) with the actual image. Hence by having the code for the drawing methods in this MC, things line up nicely (i.e. clicking in the upper left of the image registers as 0,0)

Now, all I want to do is simply constrain the ability to draw within that 400x400px canvas area on screen. I've tried a few dozen permutations on hitTesting the canvas area, and everything I try simply knocks out the ability to draw anything at all. It's probably just pathing issues, but I can't get it.

What I want is probably an if/else statement that checks to see if the mouse is in that area, and if so, lets you do the drawing method. If not, nothing should happen

Any help guys? I'd really appreciate it.

Drawing Methods And Constraining With HitTest
Thanks to the samples and stuff on this board and other places online, I've got the beginnings of a nice little online app that will eventually be used to do measurements on medical images. This really isn't that relevant to the problem I've got though.

This has got to be simple, but I can't get it to work.

The file is structured as following:

-main stage has an MC into which a medical image is loaded from disk (just a jpeg)
-one layer above that is the "canvas" MC. This MC has two layers, a simple square border and the code to enable the straight line drawing methods. Because we are later going to do calculations on the lines, the drawing space needs to be in proper alignment (coordinates-wise) with the actual image. Hence by having the code for the drawing methods in this MC, things line up nicely (i.e. clicking in the upper left of the image registers as 0,0)

Now, all I want to do is simply constrain the ability to draw within that 400x400px canvas area on screen. I've tried a few dozen permutations on hitTesting the canvas area, and everything I try simply knocks out the ability to draw anything at all. It's probably just pathing issues, but I can't get it.

What I want is probably an if/else statement that checks to see if the mouse is in that area, and if so, lets you do the drawing method. If not, nothing should happen

Any help guys? I'd really appreciate it.

Drawing A Circle
This may seem simple to you guys, but I haven't used flash for ages...so I'm a little rusty.

Anyway, what I want to do is to make an animation where it looks like a circle is being drawn - like you would by hand. I've tried using a mask, but just can't get it to work.

I was wondering if I can do this using actionscript, I'd prefer to use actionscript.

Drawing A Circle
Hi

Using FlashMX. I want to make an animation where it looks like someone is drawing a circle. I know how to do this without actionscript, but I'd much prefer to use actionscript to do this. Please someone show me the light!

BTW I haven't used flash for a while, so I'm VERY rusty...

Drawing A Circle
Hi!

I want to make am animation using flash.
What i am trying to do is make it look like it is drawing a circle.
So if someone would help me I would be real happy.

Drawing A Circle
Hi all

I have this really simple AS3 code which rotates a movieclip counterclockwise, like this

import fl.transitions.*;
import fl.transitions.easing.*;

TransitionManager.start(timerHand, {type:Rotate, duration:1, ccw:true, degrees:360});

How does one go about to draw a full circle using the TransitionManager? I want the timerHand to draw itself as it moves in a circular motion.

Thanks

Drawing A Circle
Hi
I have some problem drawing circle using AS 3.0
Here is my code and help me to correct my mistake. I get this error msg " Access of undefined property cir". Thank you


Code:
<mx:Script>
<![CDATA[

import flash.display.*;

var cir:Shape;

cir.graphics.drawCircle(50,50,100);
]]>
</mx:Script>

Circle Drawing?
I'm trying to create a dynamic drawing application but when I'm creating a circle with this code I get an extra line after the circle is finished extending from the end to some point out in space. When I don't fill it the outline is fine and when I don't put an outline it's fine?









Attach Code

//========================================================================================================================================================================
// draw circle function
//========================================================================================================================================================================
MovieClip.prototype.drawCircle = function (radius, cntX, cntY) {
var toRadians:Number = Math.PI/180;

this.moveTo(cntX, cntY);
this.lineTo(radius, 0);
this.lineStyle(_root.drawingLineSize,_root.drawingLineColor,75);

var a:Number = 0.268; // tan(15)
for (var i=0; i < 12; i++) {
var endx = radius*Math.cos((i+1)*30*toRadians);
var endy = radius*Math.sin((i+1)*30*toRadians);
var ax = endx+radius*a*Math.cos(((i+1)*30-90)*toRadians);
var ay = endy+radius*a*Math.sin(((i+1)*30-90)*toRadians);
this.curveTo(ax, ay, endx, endy);
}
this._x = cntX;
this._y = cntY;


}

//========================================================================================================================================================================
// draw circle function
//========================================================================================================================================================================
function drawCircleShape():Void {
var startX:Number = _root.mapSection.mainMap.vectorMap._xmouse;
var startY:Number = _root.mapSection.mainMap.vectorMap._ymouse;

onMouseMove = function (){
var ref:MovieClip = _root.mapSection.mainMap.vectorMap.createEmptyMovieClip("circleMC"+_root.nextItemDepth, _root.nextItemDepth);
_root.clipsArray.push(ref);
//trace(_root.drawingLineSize);
ref.beginFill(_root.drawingFillColor, 25);

var startingX = startX;
var startingY = startY;
var endingX = _root.mapSection.mainMap.vectorMap._xmouse;
var endingY = _root.mapSection.mainMap.vectorMap._ymouse;

var thisRadius = Math.round(endingX - startingX);
trace(thisRadius);
ref.drawCircle(thisRadius, startX, startY);
ref.endFill();
}
}

Circle Drawing
Hi,

[atchmnt:FLA from senocular]
I hope you can help me in this.

Here I what i need is :

Start drawing first circle and when first circle is on half way, Start second circle.
same way second and third circles.
and after completing 3 circles, just gotoAndPlay 2nd Frame .

that s all.

nasih

Drawing A Circle With AS
Hi all,

I'm trying to draw a circle using ActionScript instead of doing it on the timeline.
I found this script, which just draws the circle in one frame, but I need to see the circle being drawen. Can anyone help with this, or point me in the right direction.


ActionScript Code:
this.createEmptyMovieClip("drawing_mc", 5);var x = 275;var y = 200;var R = 100;var a = R*0.4086;var b = R*0.7071;drawing_mc.lineStyle(5, 0xff0000, 90);drawing_mc.moveTo(x-R, y);drawing_mc.curveTo(x-R, y-a, X-b, Y-b);drawing_mc.curveTo(x-a, y-R, x, y-R);drawing_mc.curveTo(x+a, y-R, x+b, y-b);drawing_mc.curveTo(x+R, y-a, x+R, y);drawing_mc.curveTo(x+R, y+a, x+b, y+b);drawing_mc.curveTo(x+a, y+R, x, y+R);drawing_mc.curveTo(x-a, y+R, x-b, y+b);drawing_mc.curveTo(x-R, y+a, x-R, y);

Circle Drawing
Hi,

[atchmnt:FLA from senocular]
I hope you can help me in this.

Here I what i need is :

Start drawing first circle and when first circle is on half way, Start second circle.
same way second and third circles.
and after completing 3 circles, just gotoAndPlay 2nd Frame .

that s all.

nasih

AS2 - MovieClip Drawing Methods - Adding 'border' To Image
Hello.

I am producing a standalone app which loads images from a local directory using MovieClipLoader - no problems there. I am setting the width and height (onLoadInit 200x133) so that if someone were to drop in an oversized image into the directory it wouldn't ruin the look. Finally I am adding a 'border' using the drawing methods. The border works fine if the image is exactly the right size (200x133) but if the original image is bigger then when reduced in size in the mc the border seems to scale in proportion to the original image??? There is probably a simple explanation for this...any advice? I know it will be easier to set the orignal image to the right size (which I probably will do) but I am curious how to do it the other way.


Code:
var nWidth = 134;
var nHeight = 201;
var imgLoad = new MovieClipLoader();
imgLoad.loadClip("commander.jpg", img_commander);
imgLoad.onLoadInit = function (img_commander){
img_commander._width = 133;
img_commander._height = 200;

with (img_commander) {
beginFill(0xFFFFFF, 100);
moveTo(-1, -1);
lineTo(nWidth, -1);
lineTo(nWidth, nHeight);
lineTo(-1, nHeight);
lineTo(-1, -1);
endFill();
}
}
Please don't laff at my code!

Animate The Drawing Of A Circle
I don't necessarily consider myself a newbie, but this question begs to differ. How do you simulate the drawing of a simple circle? From nothing to a whole circle going clockwise. I have played with this for about 2 days and feel like an idiot.

Please help

Drawing A Circle Dynamically?
Hi guys
Can anyone help me convert the code below to create a circle using the curveTo() command.
Would really appreciate it
Cheers
Ol

_root.onMouseDown = function() {
x0 = _root._xmouse;
y0 = _root._ymouse;
draw();
};
function draw() {
_root.onMouseMove = function() {
x1 = _root._xmouse;
y1 = _root._ymouse;
_root.clear();
_root.lineStyle(1, 0x000000, 100);
_root.moveTo(x0, y0);
_root.lineTo(x0, y1);
_root.lineTo(x1, y1);
_root.lineTo(x1, y0);
_root.lineTo(x0, y0);
};
}

Circle Drawing Animation
I want to have an animation of a circle being drawn. ie starts as dot and the dot grows so the final frame is the full circle.

Drawing A Circle Animation
Can anybody help me? I have a client who wants an animation of a brush drawing a circle. I have the image they want to use, made in illustrator, converted from a tiff to a .png in photoshop and imported into flash- then traced to take the background out. I've used a mask but it does not give the effect I'm looking for. It would work if I could find an animated pie chart going from 0% to 100% and using it as a mask (which would give the illusion of drawing the circle, but I can't figure out how to do that. Any suggestions?

thanx for any support,

Cobyco

How To Get Rid Of That Circle Thingy When Your Drawing
Somehow, I tapped some settings to have a little circle thing in the corner or the shape tool. THis little circle prevents me from drawing my usually stuff because I cannot scroll seemlessly to create rectangles and circles the way I want. How do I get rid of this thingy?

[CS3] Drawing Circle Over Time...
I am attempting to create circles in a diagram over time. I know how to draw the circle dynamicly but unable to render the circle over time so you can see it draw itself on stage. What's the trick?

Thanks!

OOP Newbie - Help Drawing A Circle
Hi All,

I'd say I'm fairly advanced when it comes to AS2, but I'm having real problems trying to achieve the most simplest things using AS3 and OOP methods.

I'm building my portfolio website. I've created a document class which I want to behave as the central class that builds everything (I'm assuming this is a good way of doing things?).

From within this class all I want to do is draw a circle dynamically - and I want to use another class to draw it (which I've called Circle). Here's the code for the document class -


ActionScript Code:
package
{
    import com.spiralstatic.drawing.Circle;
   
        import flash.display.MovieClip;
        import flash.display.StageAlign;
        import flash.display.StageScaleMode;
   
    public class SpiralStatic extends MovieClip
    {            
        private var circle:Circle = new Circle();
       
        public function SpiralStatic():void
        {
            stage.scaleMode = StageScaleMode.NO_SCALE;
            stage.align = StageAlign.TOP_LEFT;
           
            this.addChild(circle);

        }
    }
}

And I've created the Circle class which looks like this -


ActionScript Code:
package com.spiralstatic.drawing
{
    import flash.display.Sprite;
    import flash.display.Graphics;

    public class Circle extends Sprite
    {
        public function Circle()
        {
            var shapes:Sprite = new Sprite();
            var gr:Graphics = shapes.graphics;

            gr.lineStyle(6, 0x0000FF, .5);
            gr.beginFill(0xFF0000, .5);
            gr.drawCircle(50, 50, 50);
            gr.endFill();
           
            shapes.x = stage.stageWidth/2;
            shapes.y = stage.stageHeight/2;
            addChild(shapes);
        }
    }
}


Now I'm a total newb when it comes to OOP so I'm probably going about all this the wrong way. I get an error when I publish this and all I want to do is make the document class draw a circle.

What do I have to do to make this work? Please help as it's driving me insane!

Thanks very much,

Matt

Drawing Circle Segments
Hi,

I'm having a bit of trouble with trigonometry & actionscript.

The first thing I'm trying to do is draw 8 pie segments congruently (all 45 degrees).

How I tried to approach it was like this.

my start angle = 0

my end angle =45

draw

my start angle = 45

my end angle =90

and so on.

I've been working from examples that I found on the net but I'm having a real block trying to get it going.


ActionScript Code:
package
{
    import flash.display.Graphics;
    import flash.display.MovieClip;
    import flash.display.Shape;
    import flash.events.TimerEvent;
    import flash.utils.Timer;
    import org.flashdevelop.utils.xtrace
   
    public class SnapCounter extends MovieClip
    {
        private var _radius:int = 57
       
        private var _shape:Shape=new Shape();
       
        private var _graphics:Graphics = _shape.graphics;
       
        private var startAngle:Number = 0;
       
        private var lastAngle:Number=0
       
        private var _timer:Timer;
       
        private var _segments:int = 8;
       
        private var _angles:int = 360 / 8
       
        private var _duration:int = 3000 // will be the number of milliseconds to reach a snap point
       
        private var _timerInterval:int = 30 // 30 for now for arguments sake
       
        private var _totalInts:int;
       
        private var _startValue:int = 0
       
        private var _endValue:Number = 100;
       
        private var _changeValue:Number = _endValue - _startValue
       
        private var _colors:Array = new Array();
       
       
       
       
       
        public function SnapCounter()
        {
            _shape.x = 100;
            _shape.y = 100;
           
            _totalInts = Math.floor(_duration / 30);
           
            _timer = new Timer(_timerInterval, _totalInts)
           
            //_timer.addEventListener(TimerEvent.TIMER, render)
            //_timer.start()
           
            _colors=[0xff00ff,0x000000,0xffff00,0x0000ff,0x0f0f0f,0xf0f0f0,0xff000f,0xff0f0f]
           
           
            this.addChild(_shape)
           
            Render(_segments)

        }
       
       
       
        public function CircleSegmentTo(x:Number, y:Number ,a1:Number, a2:Number, r:Number, dir:Number):void {
           
             var diff:Number = Math.abs(a2 - a1);
            
             var divs:Number = Math.floor(diff/(Math.PI/4)) + 1;
            
             var span:Number = dir * diff / (2 * divs);
            
             var rc:Number = r / Math.cos(span);
            
             _graphics.moveTo(x + Math.cos(a1) * r, y + Math.sin(a1) * r);
            
             for (var i:int=0; i<divs; ++i) {
                  a2 = a1+span; a1 = a2+span;
                  _graphics.curveTo(
                       x+Math.cos(a2)*rc,
                       y+Math.sin(a2)*rc,
                       x+Math.cos(a1)*r,
                       y+Math.sin(a1)*r
                  );
             };
            
        }
       
       
        public function Render(pSegments:int):void
        {
            var startAngle:Number;
           
            //_graphics.clear();
           
            for (var i:int = 0; i < pSegments; i++ )
            {
               
           
                var p:int = i + 1;
                   
                var pt:int = (100 / pSegments) * p
               
               
                   
                var endAngle:Number = 2 * Math.PI * (pt) / 100;
               
                lastAngle=endAngle
               
                if (i == 0)
                {
                   
                     startAngle= 0;
                   
                }
               
                xtrace("endAngle "+endAngle)
               
               
               
                if (endAngle != startAngle)
                {
                   
                    _graphics.lineStyle(2,0,100);
                    _graphics.beginFill(_colors[i],100);
                    _graphics.lineTo(this._radius,0);
                    CircleSegmentTo(0, 0, startAngle, endAngle, _radius, -1);
                   
                    startAngle = lastAngle;
                   
                    _graphics.lineTo(0,0);
                    _graphics.endFill();
                   
                }      
           
            }
   
    }
       
       
       
       
   
       
    }
   
}

Drawing Circle With Actionscript
Hi all,

I'm trying to draw a circle using ActionScript instead of doing it on the timeline.
I found this script, which just draws the circle in one frame, but I need to see the circle being drawen. Can anyone help with this, or point me in the right direction.


ActionScript Code:
this.createEmptyMovieClip("drawing_mc", 5);
var x = 275;
var y = 200;
var R = 100;
var a = R*0.4086;
var b = R*0.7071;
drawing_mc.lineStyle(5, 0xff0000, 90);
drawing_mc.moveTo(x-R, y);
drawing_mc.curveTo(x-R, y-a, X-b, Y-b);
drawing_mc.curveTo(x-a, y-R, x, y-R);
drawing_mc.curveTo(x+a, y-R, x+b, y-b);
drawing_mc.curveTo(x+R, y-a, x+R, y);
drawing_mc.curveTo(x+R, y+a, x+b, y+b);
drawing_mc.curveTo(x+a, y+R, x, y+R);
drawing_mc.curveTo(x-a, y+R, x-b, y+b);
drawing_mc.curveTo(x-R, y+a, x-R, y);

Drawing A Circle Or Arc Using JSFL API
Can someone tell me how to draw a circle or arc using the JavaScript API? I have figured out all of the math for the location of the points but am not sure the steps to actually do the drawing. Here is the code I have tried but the path.makeshape seem to convert the arcs into closed paths ( like a D instead of C).

I have also tried the addNewOval which does draw an oval but then I can't seem to get to the properties of the oval. When I test the type it is a shape and a group but not an oval. any ideas?


var myPath = fl.drawingLayer.newPath();
for (i = 0; i < sections; i++)
{
var rotateMat = new Matrix33();
rotateMat.setRotation(theta * i);
var p0t = p0.transform(rotateMat);
var p1t = p1.transform(rotateMat);
var p2t = p2.transform(rotateMat);
var p3t = p3.transform(rotateMat);

myPath.addCubicCurve(p0t.x, p0t.y, p1t.x, p1t.y, p2t.x, p2t.y, p3t.x, p3t.y);
}
myPath.makeShape(true, false);

Circle..drawing By Script..How ? Please
Hi,

please check the attchmnt.

With this i want to get just a circle drawing effect.
First draw outer circle, then draw second inner circle and last third inner circle.

thats all

Please give me some solutions

Can't Display Drawing Circle
I try to display a simple circle in the stage but it doesn't work.

Here's the code:

package {

import flash.display.Sprite;
import flash.display.Shape;

public class circles extends Sprite {

public function circles() {

var green:Shape = _createCircle(0x00FF00, 10);
green.x = 25;
green.y = 25;

addChild(green);
}


private function _createCircle(color: uint, radius: int):Shape {
var circle:Shape = new Shape();
circle.graphics.beginFill(color);
circle.graphics.drawCircle(0, 0, radius);
circle.graphics.endFill();
return circle;
}
}
}



What's wrong with the code?

Circle..drawing By Script..How ? Please
Hi,

please check the attchmnt.

With this i want to get just a circle drawing effect.
First draw outer circle, then draw second inner circle and last third inner circle.

thats all

Please give me some solutions

Animate The Drawing Of A Circle
How do you simulate the drawing of a simple circle? From nothing to a whole circle going clockwise. I have played with this for about 2 days and feel like an idiot.

Please help

Animation Of Drawing Circle
Last edited by cren : 2005-12-16 at 08:02.
























Hi,
I just need to make AS animation of drawing (with easing) circle. Can somebody help me/point me on some tutorial?

THANK YOU VERY MUCH!
cren

Animate Drawing The Outline Of A Circle?
I know this must be simple, but I just can't figure out how to do it. Can somebody tell me how?
In my flash movie, I want the user to see the outline of a circle being drawn.

thanks in advance!

Drawing A Small Circle On Click
I'm not a Flash developer but I need to complete a task in flash before this evening. I need to have a map on stage, click on it and a red dot appears where I click, then the coordinates of that click are passed to a web page which will manipulate the database. The web stuff is someone elses problem. Can anyone tellme if this is possible and if it is attainable with limited knowledge of Flash. Thanks

Drawing A Circle In Flash Mx, Help Needed
I got this code from colin moocks book, Im think I understand most of it apart from the role that control distance and control points play

.. could some some please explain what it is... please


what does this do.. I drawing would be great. if not some simpler code and an explaination of the principles ?



PHP Code:



method draw circle..

// method draw circle..
// we must calulate the points on the circle and draw lines between them..
// 

// moock pg 643 example r2
MovieClip.prototype.drawCircle = function(x, y, r, segments) {

    // Varibles to hold the end and control points of each curve
    var endX, endY, controlX, controlY;
    // use 8 segments if not specified.
    if (segments == undefined) {
        segments = 8;
    }
    // caluculate how many degrees are in each segment
    // (360/ segments) and convert to radians.
            // yeah

    var segmentAngle = (360/segments)/180*Math.PI;
    // calculate the distanse to the control point of each curve.
    var controlDist = r/Math.cos(segmentAngle/2);
    //Start drawing on the circles positive x axis.
    this.moveTo(x+r, y);
    //Draw the circle segments
    for (var i = 1; i<=segments; i++) {
        // calculate the end point of this curve.
        endX = x+r*Math.cos(i*segmentAngle);
        endY = x+r*Math.sin(i*segmentAngle);
        // calculate the control point of this curve
        controlX = x+controlDist*Math.cos(i*segmentAngle-segmentAngle/2);
        controlY = x+controlDist*Math.sin(i*segmentAngle-segmentAngle/2);
        // Draw this curve.
        this.curveTo(controlX, controlY, endX, endY);
    }
};
this.lineStyle(1);
this.drawCircle(200, 200, 150); 




//What is the control distance?



This part just confuses me.I need it drawn of a link to a tutorial..


PHP Code:



var controlDist = r/Math.cos(segmentAngle/2); 










[/code]

Flash Preloader That Looks Like A Circle Drawing Itself
Hi everyone - I'd like to make a simple preloader that looks like a stroked circle is being drawn - when the circle connects with itself, the loading is complete.

It sounds easy enough but I'm not sure how to mask off the circle. I tried using another circle as a mask and rotating it into place but it doesn't quite have the effect I want.

THanks for your help!

Drawing A Circle On Enter Frame
could anybody point me in the direction on how to create a circle on enterframe....basically, a circular loading bar. As the percent loaded goes up, more of the circle is created.

Drawing N Movieclips Dynamically In A Circle
I know how to attach the movieclips, and how to adjust their location, but I am unsure on the math necessary to pull this off. The number of movieclips to be placed will be constantly increasing, and I want them to be placed in a circle evenly. I can divide the distance of movement between each one, but I don't know how to make them move along the circle.

The "dork method" way of doing this would be to align the 0,0 point of each movieclip in the middle of the circle, and simply rotate accordingly.

Can anyone think of a fairly more elegant method?

Drawing A Dynamic Pie-chart / Graph -circle
Hello!
I made a little poll which shows five most common answers graphically - with bars.
It would be neat if you could show same information in a pie chart! Does anybody know how to do that?

My bar-graph works basically like this(simple):

multipler = (bar_max_height / amount_of_answers)
bar1_height = (answers1 * multipler)
bar2_height = (answers2 * multipler)
...

Like that it would be super-easy to get out how many degrees answer1..etc would take from the chart.
But how to draw a semicircle in flash based on that information? And how to tell where the next pie will start(in fact that it is fairly simple to count sum of degrees taken by previous slices).

Any ideas or good tutorials around?

(I think that this is irrelevant, but information is stored in MySQL and accessed via PHP)

Get A 'circle' That Restrict My Movement When Drawing With Tools...
Hi.
This might sound a little weird, but when I try to draw a circle, or transform an image, a strange circle appears right next to my cursor and it kind of restricts the grade of accuracy I can use when resizing or dragging things... I wonder what it is and what it is doing next to my cursor because I don't remember enabling anything, and I use the same Flash MX 2004 I did on my old PC and I never got it there...
I have added a JPG to take a look at for you guys.

Thanks in advance

[F8] Drawing Circle Works, Putting It In MC Doesn't
Here's the code I'm using. Many thanks to the FlashKitter who originally posted most of it, sorry I forgot who that was.

So it draws the circle just fine. The only problem is I'm trying to get it to circle a movieclip that is nested in another movie clip.


Code:
MovieClip.prototype.drawCircle = function(center, rad, thisColor) {
lineColor = thisColor;
controlOffset = Math.sin(24*Math.PI/180)*rad;
lineStyle(2, lineColor);
beginFill(fillColor, fillAlpha);
moveTo(center[0], center[1]-rad);
curveTo(center[0]+controlOffset, center[1]-rad, center[0]+Math.cos(45*Math.PI/180)*rad, center[1]-Math.sin(45*Math.PI/180)*rad);
curveTo(center[0]+rad, center[1]-controlOffset, center[0]+rad, center[1]);
curveTo(center[0]+rad, center[1]+controlOffset, center[0]+Math.cos(45*Math.PI/180)*rad, center[1]+Math.sin(45*Math.PI/180)*rad);
curveTo(center[0]+controlOffset, center[1]+rad, center[0], center[1]+rad);
curveTo(center[0]-controlOffset, center[1]+rad, center[0]-Math.cos(45*Math.PI/180)*rad, center[1]+Math.sin(45*Math.PI/180)*rad);
curveTo(center[0]-rad, center[1]+controlOffset, center[0]-rad, center[1]);
curveTo(center[0]-rad, center[1]-controlOffset, center[0]-Math.cos(45*Math.PI/180)*rad, center[1]-Math.sin(45*Math.PI/180)*rad);
curveTo(center[0]-controlOffset, center[1]-rad, center[0], center[1]-rad);
endFill();
};

_root.movie1.movie2.drawCircle([movie3._x, movie3._y], radiusValue, thisColor);
Can someone help me put this problem to bed?

Again and again, Thanks.

Drawing Circles And Arcs Of A Circle With CurveTo
Hello,

I want to program a class that can draw circles, just by giving the radius, and middlepoint as parameter to the constructor of the class.

and

I want to programm a class that can draw arcs of circles, by giving paramters:
startpoint, endpoint, midllepoint
or
startpoint, angle, radius
I thought the best way to do that, is with curveTo. But unforunatedly it is hard to find out how the first two Parameters of this Mehtod work exactly. Can you give me a hint?

Maybe you got a samplecode for drawing a _perfect_ circle with curveTo?

Thanx,
Robert !

Drawing Simple Circle In Class Makes Me Go "arrghgh"
Hello,
I'm trying to draw a simple circle using a class, importing and using that class in Flash CS3. Without the class I can draw a circle just fine on the main timeline.

The following class code seems to work, but I cannot see the circle on the stage. I can even change the position and trace as it changes. I just can't see it. Am I missing something?


Code:
//in my fla file:
import xx.xx.fireworks.*;
var testRocket:Rocket = new Rocket();

//in xx/xx/fireworks/Rocket.as:
package xx.xx.fireworks {
import flash.events.Event;
import flash.display.*;

public class Rocket extends Sprite {
private var _rocket:Shape;
private var _vy:Number = 1;

public function Rocket() {
_rocket = new Shape();
_rocket.graphics.beginFill(0xFF0000,100);
_rocket.graphics.drawCircle(0,0,25);
_rocket.graphics.endFill();
_rocket.x = 50;
_rocket.y = 100;
addChild(_rocket);
addEventListener(Event.ENTER_FRAME,onEnterFrame);

}

public function onEnterFrame(event:Event):void {
_rocket.y += _vy;
trace(_rocket.y);
}
}
}
Thanks for the assist.

Overriding Base Class Methods While Calling Original Methods
I would like to write a class that extends XMLSocket. I'd like to call my class RPCSocket. Among other things, I want to add a property which indicates that the socket is 'waiting to connect'. This would mean that the connect() method of XMLSocket has been called but the CONNECT event has not yet been dispatched. I'll therefore need to override the CONNECT and CLOSE methods of XMLSocket in my class, RPCSocket.

I haven't yet seen any reason why I can't override these methods -- they are neither constant nor static nor final and do not implement an interface method (as far as I can tell) and they are inherited.

I obviously need to call the original connect() and close() methods of the XMLSocket, however. Is this code the proper way to do this? Can anyone see any particular problem with this?

code:
package {
class RPCSocket extends XMLSocket {
public var boolWaitingToConnect:Boolean = false;

public override function connect(host:String, port:int):void {
boolWaitingToConnect = true;
super.connect(host, port);
}
public override function close(host:String, port:int):void {
boolWaitingToConnect = false;
super.close();
}
}
}

Static Methods Vs. Instance Methods And Memory Usage
Hello all, I'm pretty green to OOP (at least "real" OOP) and am trying to wrap my tiny little brain around something. I understand the difference between static and instance methods in the practical sense, i.e. how the static modifier affects a method for in a class. What I'm not 100% on is memory usage and whether I should even care. Here’s my specific scenario for context:

I am creating a package for list generation, rendering and editing, there are a number of classes in the package; Item, PlainList, EditableList and DragDropList. At a minimum, one of the list constructors is passed a target movie (where to draw the list), itemName (symbol name for Item constructor) and dataList (data items for Item constructor). There is also an EventDispatcher that fires "onInitList", "onInitItem", "onSelectItem", etc. These lists could be hundreds of items long and contain sub-list instances. So, long story there could be thousands of list/item instances at a time.

The majority of methods (in pretty much all classes) could be written as static by simply passing the target instance. For public methods, I would make lightweight wrappers that call the appropriate static method, for example:


Code:

class PlainList {
public function PlainList( target:MovieClip, itemName:String, dataList:Object, margin:Number, xOffset:Number, yOffset:Number, rows:Number ){
//bunch'o'code here
}
public function draw( type:String ){
if ( type == "grid" ) PlainList.drawGrid( this );
else PlainList.drawList( this );
}
private static function drawGrid( pl:PlainList ){
//bunch'o'code here
}
private static function drawList( pl:PlainList ){
//bunch'o'code here
}
}



As I understand it, if I use static methods, the method is instantiated only once for the class and there is only one pointer to it. If I were using instance methods each method is uniquely instantiated with it's own memory space and pointer for ever instance of the class. Given that there could be thousands of class instances at a time each with 20-30 methods, does the technique described above make sense? Will I be saving memory? Is this bad OOP? And finally, although right now I am using AS2 in Flash 8, I will be updating to Flash 9 ASAP, any implications regarding AS3? For example, usage of the "protected" and "final" modifiers? Thanks.

Timed Segment
Hi

I was wondering if it was possible to have a script in my main movie that can call upon other swf's at certain times of the day.

I have a segment that runs all day and night but at 12 noon and 3 pm I would like the main movie to call upon a pre-determined clip.

Any help would be appreciated

James

[CS3] IK Segment Dragging
I'm working on a project where a user controls an "organism" made up of polygon "segments." Long story short, It's due in 5 weeks and I am stuck still trying to make the thing move. I've got a lot more work to do on this thing, and I need to get past this roadblock to continue.

Basically, the organism is defined by a sloppy DNA class. It was the best way I could think of for each organism to hold it's own set of "traits." This is working. However, getting the segments, once drawn, to follow the mouse is the problem.

I adapted the "followMouse" and "drag" functions from Actionscript 3.0 Animation: Making Things Move!. I know that the problem probably lies with the translation from AS 3.0 to AS 2.0. Learning 3.0 at this point in the semester is not an option.

Here are the movement functions:


PHP Code:



//Inverse Kinematics drag-segments function (Keith Peters)--------------------
MovieClip.prototype.followMouse = function(CLIP, RAD, SEGS, TAPER){
    CLIP.onEnterFrame = function(){
        var newRad = RAD;
        CLIP.drag(seg0, RAD, _xmouse, _ymouse);
        for(var i = 0; i < SEGS; i++){
            newRad = newRad*TAPER;
            var segA = CLIP["seg" + i];
            var segB = CLIP["seg" + (i+1)];
            CLIP.drag(segB, newRad, segA._x, segA._y);
        }
    }
}

MovieClip.prototype.drag = function(SEG:MovieClip, LENGTH, x:Number, y:Number){
    var dx:Number = x - SEG._x;
    var dy:Number = y - SEG._y;
    var angle:Number = Math.atan2(dy, dx);
    SEG._rotation = angle * 180 / Math.PI;
    SEG._x = x - Math.cos(angle) * LENGTH;
    SEG._y = y - Math.sin(angle) * LENGTH;
}
//-----------------------------------------------------------------------------




And here is the "makeOrganism" function, if it's any help:


PHP Code:



//ORGANISM-------------------------------------------------------------------------------
var num = 0;
function makeOrganism(DNASTRING:String, X, Y){
    var organism = this.createEmptyMovieClip("organism"+num, D);
    D++;
    //trace(DNASTRING.length);
    if(DNASTRING.length < 10){
        for(var i = 0; i < (10-DNASTRING.length); i++){
            DNASTRING+="0";
        }
    }
    this["dna"+num] = new DNA();
    this["dna"+num].dnaString = DNASTRING;
    //this["dna"+num].setDnaString(DNASTRING);
    trace(this["dna"+num].dnaString);
    //Trait construction-------------------------------------------
    this["dna"+num].setTraits();
    var radius = (Number(this["dna"+num].gRadius)+1)*5;
    var sides = Number(this["dna"+num].gSides)+3;
    var segNum = Number(this["dna"+num].gSegNum)+1;
    var segTaper = 1-(Number(this["dna"+num].gSegTaper)*0.01);
    var limbNum = Number(this["dna"+num].gLimbNum);
    var limbSegNum = Number(this["dna"+num].gLimbSegNum);
    var limbSegTaper = 1-(Number(this["dna"+num].gLimbSegTaper)*0.01);
    var fill = color[Number(this["dna"+num].gFill)];
    var stroke = color[Number(this["dna"+num].gStroke)];
    var mutateProb = Number(this["dna"+num].gMutateProb)*0.1;
    //-------------------------------------------------------------
    //Draw Organism------------------------------------------------
    var newRadius = radius;
    for(var i = 0; i < segNum; i++){
        organism.createEmptyMovieClip("seg"+i, D);
        D++;
        organism["seg"+i].drawPoly(sides, newRadius, fill, stroke);
        newRadius = newRadius*segTaper;
    }
    //-------------------------------------------------------------
    organism.followMouse(organism, radius, segNum, segTaper);
    num++;
}
//---------------------------------------------------------------------------------------




If necessary, I can provide the full code, in all it's kludgey glory.

Any help/comments/divine miracles would be appreciated.

-cr0ybot

[AS2 CS3] IK Segment Dragging
I'm working on a project where a user controls an "organism" made up of polygon "segments." Long story short, It's due in 5 weeks and I am stuck still trying to make the thing move. I've got a lot more work to do on this thing, and I need to get past this roadblock to continue.

Basically, the organism is defined by a sloppy DNA class. It was the best way I could think of for each organism to hold it's own set of "traits." This is working. However, getting the segments, once drawn, to follow the mouse is the problem.

I adapted the "followMouse" and "drag" functions from Actionscript 3.0 Animation: Making Things Move!. I know that the problem probably lies with the translation from AS 3.0 to AS 2.0. Learning 3.0 at this point in the semester is not an option.

Here are the movement functions:


PHP Code:



//Inverse Kinematics drag-segments function (Keith Peters)-------------------- MovieClip.prototype.followMouse = function(CLIP, RAD, SEGS, TAPER){     CLIP.onEnterFrame = function(){         var newRad = RAD;         CLIP.drag(seg0, RAD, _xmouse, _ymouse);         for(var i = 0; i < SEGS; i++){             newRad = newRad*TAPER;             var segA = CLIP["seg" + i];             var segB = CLIP["seg" + (i+1)];             CLIP.drag(segB, newRad, segA._x, segA._y);         }     } } MovieClip.prototype.drag = function(SEG:MovieClip, LENGTH, x:Number, y:Number){     var dx:Number = x - SEG._x;     var dy:Number = y - SEG._y;     var angle:Number = Math.atan2(dy, dx);     SEG._rotation = angle * 180 / Math.PI;     SEG._x = x - Math.cos(angle) * LENGTH;     SEG._y = y - Math.sin(angle) * LENGTH; } //----------------------------------------------------------------------------- 




And here is the "makeOrganism" function, if it's any help:


PHP Code:



//ORGANISM------------------------------------------------------------------------------- var num = 0; function makeOrganism(DNASTRING:String, X, Y){     var organism = this.createEmptyMovieClip("organism"+num, D);     D++;     //trace(DNASTRING.length);     if(DNASTRING.length < 10){         for(var i = 0; i < (10-DNASTRING.length); i++){             DNASTRING+="0";         }     }     this["dna"+num] = new DNA();     this["dna"+num].dnaString = DNASTRING;     //this["dna"+num].setDnaString(DNASTRING);     trace(this["dna"+num].dnaString);     //Trait construction-------------------------------------------     this["dna"+num].setTraits();     var radius = (Number(this["dna"+num].gRadius)+1)*5;     var sides = Number(this["dna"+num].gSides)+3;     var segNum = Number(this["dna"+num].gSegNum)+1;     var segTaper = 1-(Number(this["dna"+num].gSegTaper)*0.01);     var limbNum = Number(this["dna"+num].gLimbNum);     var limbSegNum = Number(this["dna"+num].gLimbSegNum);     var limbSegTaper = 1-(Number(this["dna"+num].gLimbSegTaper)*0.01);     var fill = color[Number(this["dna"+num].gFill)];     var stroke = color[Number(this["dna"+num].gStroke)];     var mutateProb = Number(this["dna"+num].gMutateProb)*0.1;     //-------------------------------------------------------------     //Draw Organism------------------------------------------------     var newRadius = radius;     for(var i = 0; i < segNum; i++){         organism.createEmptyMovieClip("seg"+i, D);         D++;         organism["seg"+i].drawPoly(sides, newRadius, fill, stroke);         newRadius = newRadius*segTaper;     }     //-------------------------------------------------------------     organism.followMouse(organism, radius, segNum, segTaper);     num++; } //--------------------------------------------------------------------------------------- 




If necessary, I can provide the full code, in all it's kludgey glory.

Any help/comments/divine miracles would be appreciated.

-cr0ybot

Copyright © 2005-08 www.BigResource.com, All rights reserved