# OOP - basic test

**URL:** <https://forum.kirupa.com/t/oop-basic-test/324787>\
**Category:** flash\
**Created:** [September 8, 2011, 9:28pm UTC](https://forum.kirupa.com/t/oop-basic-test/324787 "2011-09-08T21:28:51Z")\
**Posts on this page:** 1\
**Page:** 1

<div class="post-metadata">

**Author:** ![jeancnicolas](https://avatars.discourse-cdn.com/v4/letter/j/7bcc69/32.png) [@jeancnicolas](https://forum.kirupa.com/u/jeancnicolas)\
**Post date:** [September 8, 2011, 9:28pm UTC](https://forum.kirupa.com/t/oop-basic-test/324787/1 "2011-09-08T21:28:51Z")

</div>

Hiya - Itd be great if someone could help me out here … I want to use OOP as a test, to put an MC on the Stage.  
Here goes - be patient - im trying to also keep it as clean as poss for peeps to actually get in here and help…

I have the following:  
my FLA with doc class Main.as,  
Main.as (calls Task)  
Task.as (calls Ball)  
Ball.as (Draws a circle)

[1] Main just tells Task to do what ever he’s meant to do.  
[2] Task gets the Ball class, and puts an instance of Ball on the Stage.

Simple … &I know I could just put Ball on the Stage in my doc class - but thats not the aim.

Ill just show my simplified packages - because this is where I can learn how to make this work… (Thanks in advance 😉  
Main.as

```auto
public class Main extends MovieClip {  
        public function Main()  
        {  
  	initiate();
        }  
        public function initiate()
        {
        var ball:Task = new Task();
	addChild(ball);
        }
    }  

```

Task.as

```auto
public class Task extends Sprite {  
        private var b1:Ball;  
  
        public function Task() 
	{  
            b1 = new Ball(20);  
            addChild(b1);  
        }  
    }

```

Ball.as

```auto
import flash.display.Sprite;	
	public class Ball extends Sprite
	{
		private var radius:Number;
		private var color:uint;
		
		public function Ball(radius:Number = 40)
		{
			this.radius = radius;
			this.color = Math.random()*color;
			init();	
		}
		public function init():void
		{
			graphics.beginFill(color);
			graphics.drawCircle(0,0,radius);
			graphics.endFill();		
		}
	}	

```

OK - so that works … BUT I dont know why! Thats not my stupid question - but rather about why it does - Because if you noticed - for it to work - I have to ‘addChild(ball)’ in Main.as to get it to go on the stage… But I want Task.as to do that when I ask ‘addChild(b1)’ to do so … And also just by calling Task - it does what I want it to - without having to declare what in the Main class…

ANY TIPS or ADVICE would be GREATLY APPRECIATED!  
🙂
