# Accessing class objects via the name

**URL:** <https://forum.kirupa.com/t/accessing-class-objects-via-the-name/266864>\
**Category:** flash\
**Created:** [July 25, 2008, 12:37am UTC](https://forum.kirupa.com/t/accessing-class-objects-via-the-name/266864 "2008-07-25T00:37:30Z")\
**Posts on this page:** 1\
**Page:** 1

<div class="post-metadata">

**Author:** ![adnan794](https://avatars.discourse-cdn.com/v4/letter/a/8edcca/32.png) [@adnan794](https://forum.kirupa.com/u/adnan794)\
**Post date:** [July 25, 2008, 12:37am UTC](https://forum.kirupa.com/t/accessing-class-objects-via-the-name/266864/1 "2008-07-25T00:37:30Z")

</div>

Hello

I have a class name Contents I am creating 5 objects of this class. Is there a way to keep track of the instance names assigned to the objects. What I am doing is get all the objects of Contents class and make button out of these and when user clicks a button the I want to reterieve descrioption from Contents class but I dont have any mean of storing the instance name. I think I am not making any sense so here is some code

```auto

public class TestContent extends EventDispatcher
	{
		//Class properties
		
		private var _desc:String;
		
		private static var _children:Array = new Array();

		// Class Constructor
		public function TestContent(name:String, desc:String)
		{
			// I want to store the name assigned to this object so I can use this later
                         this.instanceName = name;
			_desc = desc;
			
			TestContent._children.push(this);
			
		}
		public function get name():String
		{
			return this.instanceName;
		}
	
	    public function get desc():String
		{
			return _desc;
		}
            public static function getChildren():Array
		{
			return _children;
		}

```

So in another class I am using the number of objects of this class to create buttons

```auto

//Some other class

parentSprite:Sprite = new Sprite;
var mArray:Array = new Array;
mArray = TestContents.getChildren();

for (i = 0; i<mArray.length; i++)
{
var mc:MovieClip = new MovieClip(mArray*)
parentSprite.addChild(mc);
}
parentSprite.addEventListener(MouseEvent.CLICK, onClikc);

public function onClick(e:MouseEvent):void
{
// here I wanna use the instance name of the TestContents object to call the desc property
trace(e.target.desc);
}

```

I hope I am making sense here

Thanks in advance
