example code from class

stage.frameRate = 31;

//values to clamp to
var smallRadius:Number = 10;
var largeRadius:Number = 100;

//startup radius
var sphereRadius:Number = 50;

//base container
var container:Sprite = new Sprite();
container.x = stage.stageWidth/2;
container.y = stage.stageHeight/2;

//graphic container
var sphere:Shape = new Shape();

//create x fps loop
this.addEventListener(Event.ENTER_FRAME, mainLoop);

//function called on every frame
function mainLoop(event:Event):void {

//get the distance of the mouse to the object
var distToMouseX:Number = clamp(container.mouseX,smallRadius,largeRadius);

//compute the radius
sphereRadius = largeRadius + smallRadius – distToMouseX;

//draw the circle


//utility function to clamp “val” to a particular range
function clamp(val:Number, min:Number, max:Number){
return Math.max(min, Math.min(max, val))


Leave a Reply

Fill in your details below or click an icon to log in:

WordPress.com Logo

You are commenting using your WordPress.com account. Log Out /  Change )

Google+ photo

You are commenting using your Google+ account. Log Out /  Change )

Twitter picture

You are commenting using your Twitter account. Log Out /  Change )

Facebook photo

You are commenting using your Facebook account. Log Out /  Change )


Connecting to %s