Get stage.Width from custom class

I have a custom class that extends MovieClip and cannot of the life of me figure out how to get the stage width from within the class. trace(stage) returns null, as well as trace(parent).

here is my class:


// define package
package 
{
	// import MovieClip class
	import flash.display.Stage;
	import flash.display.MovieClip;
	
	// define class within package, extend MovieClip
	public class Circle extends MovieClip
	{
		var maxRadius:uint;
		var fillColor:Number = 0xFF0000;
		
		public function Circle ()
		{
			//trace(root); // traces "[object MainTimeline]"
			trace(this.parent);

			maxRadius = 30;
			//this.x = __x;
			//this.y = __y;
			//this.radius = __radius;
			
			drawCircle();
			
		}
		
		private function drawCircle ()
		{
			var radius = Math.random() * maxRadius + 4;
			this.graphics.clear();
			this.graphics.beginFill(fillColor);
			this.graphics.drawCircle (0, 0, radius);
		}
	}
}

and the code in the main timeline:


// instantiate new instance of Circle
var myCircle:Circle = new Circle();

// attach instance myCircle to stage
addChild(myCircle);

Any help would be appreciated! :jail:

The easiest way is to pass an instance of the stage in the constructor.


var myCircle:Circle = new Circle(stage);

You could also just pass the width.


var myCircle:Circle = new Circle(stage.stageWidth);

That is one solution, but stage.width should be accessible within a class that extends MovieClip. I’m trying to understand what I am missing here.

What you’re missing is that the stage is only inherently accessible to the document class.

I read in the live docks that the stage is accessible in all display objects.