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
  • Last Modified:

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();
 
                addChild(circle);

Open in new window

0
lexshine
Asked:
lexshine
  • 5
  • 4
1 Solution
 
Aneesh ChopraCommented:
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();
 
addChild(circle);
// 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

Open in new window

0
 
lexshineAuthor 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
 
lexshineAuthor Commented:
the point from which it grows appears to be at the bottom right of the circle.
0
VIDEO: THE CONCERTO CLOUD FOR HEALTHCARE

Modern healthcare requires a modern cloud. View this brief video to understand how the Concerto Cloud for Healthcare can help your organization.

 
Aneesh ChopraCommented:
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
 
lexshineAuthor 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;

Open in new window

0
 
Aneesh ChopraCommented:
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
 
lexshineAuthor Commented:
you will have to add .as and .fla as I couldnt attach the zip file with the proper filenames.


circle-test.zip
0
 
Aneesh ChopraCommented:
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
 
lexshineAuthor Commented:
yep, that did the trick.. thanks!
0

Featured Post

Concerto Cloud for Software Providers & ISVs

Can Concerto Cloud Services help you focus on evolving your application offerings, while delivering the best cloud experience to your customers? From DevOps to revenue models and customer support, the answer is yes!

Learn how Concerto can help you.

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