# Get stage.Width from custom class

**URL:** https://forum.kirupa.com/t/get-stage-width-from-custom-class/262019
**Category:** flash
**Created:** [June 2, 2008, 5:28pm UTC](https://forum.kirupa.com/t/get-stage-width-from-custom-class/262019 "2008-06-02T17:28:41Z")
**Posts on this page:** 5
**Page:** 1

<div class="post-metadata">

### Author: ![Thinker2501](https://avatars.discourse-cdn.com/v4/letter/t/e0b2c6/32.png) [@Thinker2501](https://forum.kirupa.com/u/Thinker2501)
#### Post date: [June 2, 2008, 5:28pm UTC](https://forum.kirupa.com/t/get-stage-width-from-custom-class/262019/1 "2008-06-02T17:28:41Z")

</div>

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:

```auto

// 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:

```auto

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

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

```

Any help would be appreciated! :jail:

---

<div class="post-metadata">

### Author: ![Anogar](https://avatars.discourse-cdn.com/v4/letter/a/ed655f/32.png) [@Anogar](https://forum.kirupa.com/u/Anogar)
#### Post date: [June 2, 2008, 6:48pm UTC](https://forum.kirupa.com/t/get-stage-width-from-custom-class/262019/2 "2008-06-02T18:48:17Z")

</div>

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

```auto

var myCircle:Circle = new Circle(stage);

```

You could also just pass the width.

```auto

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

```

---

<div class="post-metadata">

### Author: ![Thinker2501](https://avatars.discourse-cdn.com/v4/letter/t/e0b2c6/32.png) [@Thinker2501](https://forum.kirupa.com/u/Thinker2501)
#### Post date: [June 2, 2008, 8:42pm UTC](https://forum.kirupa.com/t/get-stage-width-from-custom-class/262019/3 "2008-06-02T20:42:24Z")

</div>

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.

---

<div class="post-metadata">

### Author: ![Anogar](https://avatars.discourse-cdn.com/v4/letter/a/ed655f/32.png) [@Anogar](https://forum.kirupa.com/u/Anogar)
#### Post date: [June 3, 2008, 1:07am UTC](https://forum.kirupa.com/t/get-stage-width-from-custom-class/262019/4 "2008-06-03T01:07:46Z")

</div>

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

---

<div class="post-metadata">

### Author: ![Thinker2501](https://avatars.discourse-cdn.com/v4/letter/t/e0b2c6/32.png) [@Thinker2501](https://forum.kirupa.com/u/Thinker2501)
#### Post date: [June 5, 2008, 5:04pm UTC](https://forum.kirupa.com/t/get-stage-width-from-custom-class/262019/5 "2008-06-05T17:04:33Z")

</div>

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