Want to protect your cyber security and still get fast solutions? Ask a secure question today.Go Premium

x
• Status: Solved
• Priority: Medium
• Security: Public
• Views: 680

# Flash CS3 Actionscript 3 Scaling a circle

Once I draw the circle, I want to scale it larger or smaller.

the problem is, if I do the following

circle.height = grow;
circle.width = grow;

grow++;

the circle not only grows, it moves at an angle. I would like to scale it from the center, without it moving, just growing.

``````circle = new Sprite();
circle.graphics.beginFill(0xFFFFFF);
circle.graphics.drawCircle(450, 350, 50);
circle.graphics.endFill();

``````
0
lexshine
• 5
• 4
1 Solution

Commented:
keep registration point 0, in simple words center point of the circle in its movieClip should be 0, then it will scale at its position.
below is the updated code which should work fine..
``````var circle = new Sprite();
circle.graphics.beginFill(0xFFFFFF);
var circleWidth = 50;
circle.graphics.drawCircle(-circleWidth/2, -circleWidth/2, circleWidth);
circle.graphics.endFill();

// set x,y position of the circle once by updating following code
circle.x = 200;
circle.y = 200;
//now grow will increase it at its position
``````
0

Author Commented:
this is close to what I am looking for, except that the circle appears to grow upward and to the left as opposed to growing outward from the center.

is there a way to have it appear to grow from the center?

0

Author Commented:
the point from which it grows appears to be at the bottom right of the circle.
0

Commented:
I am sure on that using my code properly, circle will grow from center on all directions..

if it is not the case with you, then I suggest you to upload your SAMPLE FLA for review
0

Author Commented:
here is my full code for that section.

I have no idea why it grows from the bottom of the circle. when I make -circleWidth just circleWidth it grows from the top of the circle.

odd.

``````circle = new Sprite();
circle.graphics.beginFill(0xFFFFFF);
var circleWidth = 50;
circle.graphics.drawCircle(-circleWidth/2, -circleWidth/2, circleWidth);
circle.graphics.endFill();

if (cirState ==1){
cirSize=cirSize+2;
}else{
cirSize=cirSize-2;
}
if (cirSize > 80){
cirState = 2
}

if (cirSize < 10){
cirState = 1
}

circle.width = cirSize;
circle.height = cirSize;
``````
0

Commented:
provide code is not complete,

it does not tell where circle sprite has been added using  "addChild(circle)"
and it does not tell if x,y position of the circle or its parent has been changed or not.

I suggest to prepare a sample FLA with problem and attach here for quick solution
0

Author Commented:
you will have to add .as and .fla as I couldnt attach the zip file with the proper filenames.

circle-test.zip
0

Commented:
ok, got the fix

You just need to change the following line of code:
circle.graphics.drawCircle(-circleWidth/2, -circleWidth/2, circleWidth);

replace it with following:
circle.graphics.drawCircle(0, 0, circleWidth);

0

Author Commented:
yep, that did the trick.. thanks!
0

## Featured Post

• 5
• 4
Tackle projects and never again get stuck behind a technical roadblock.