# Reference to class methods

**URL:** <https://forum.kirupa.com/t/reference-to-class-methods/284167>\
**Category:** flash\
**Created:** [March 16, 2009, 9:23am UTC](https://forum.kirupa.com/t/reference-to-class-methods/284167 "2009-03-16T09:23:11Z")\
**Posts on this page:** 1\
**Page:** 1

<div class="post-metadata">

**Author:** ![ThinkKirupa](https://avatars.discourse-cdn.com/v4/letter/t/e9bcb4/32.png) [@ThinkKirupa](https://forum.kirupa.com/u/ThinkKirupa)\
**Post date:** [March 16, 2009, 9:23am UTC](https://forum.kirupa.com/t/reference-to-class-methods/284167/1 "2009-03-16T09:23:11Z")

</div>

Hi there,

I need a way to reference to object (or the class methods inside). I have a button “Add box” and when it is pressed it creates a new instance of class “MyBox”. The thing is everyone of these objects get the same name “box”.

Here’s a hint of what it’s like:

```auto
var arrBoxes:Array = new Array();
// var n:Number = 1;

function addBox(event:MouseEvent):void
{
	var box:MyBox = new MyBox();
	// var "box"+n:MyBox = new MyBox();
	// n++;
	
	factory.addChild(box);

	
	box.name = "box"+(arrBoxes.length+1)+"_mc"; // box1_mc, box2_mc, box3_mc, ...
	arrBoxes.push(box.name);
}

function changeColor(event:MouseEvent):void
{
	factory.box1_mc.setColor(red); // changeColor is public function inside of "MyBox" class
        // box1.setColor(red);
}

```

Inside of the addBox function I can easily refer to the Object with just “box” (for example box.name = …)but when in another function I cannot (and by then I might have created many "box"es).
