# Creating Objects in AS2.0 OOP technique

**URL:** <https://forum.kirupa.com/t/creating-objects-in-as2-0-oop-technique/173786>\
**Category:** flash\
**Created:** [December 29, 2005, 7:13pm UTC](https://forum.kirupa.com/t/creating-objects-in-as2-0-oop-technique/173786 "2005-12-29T19:13:44Z")\
**Posts on this page:** 1\
**Page:** 1

<div class="post-metadata">

**Author:** ![doob31](https://avatars.discourse-cdn.com/v4/letter/d/278dde/32.png) [@doob31](https://forum.kirupa.com/u/doob31)\
**Post date:** [December 29, 2005, 7:13pm UTC](https://forum.kirupa.com/t/creating-objects-in-as2-0-oop-technique/173786/1 "2005-12-29T19:13:44Z")

</div>

I am currently trying to teach myself OOP with AS 2.0, but I have hit a wall. I have a ball class that currently just creates a movieclip and places it on screen. I also have a Game class that creates the different balls. I am trying to make it so that the balls are created and named on the fly.  
My problem is that there is no reference to the ball being created. I even tried storing it in an Array, but when I reference the Array positions I get Undefined just like if I try referencing the O\_ball[bname] bname is just a variable holding the string that puts the namne togther. 3 balls are created successfully but how do I reference them or name them If I try to do it any other way I get no such property errors.

I am also almost done reading Essential AS 2.0 and I have not found anything in there with a loop that creates objects of a class.

Example:

```
private function setup_the_game():Void {
    for (var i:Number = 0; i&lt;=num_of_balls; i++) {
        create_ball(i);
    }
    O_bar = new Bar();
}

private function create_ball(num):Void {
    var bname:String = "ball"+String(num);
    O_ball[bname] = new Ball(num);
    A_balls[num] = O_ball[bname];
    trace(bname);
    trace(A_balls);
    trace(O_ball[bname]);
}
```
