# Is there a way to create an object based on a string value?

**URL:** <https://forum.kirupa.com/t/is-there-a-way-to-create-an-object-based-on-a-string-value/255016>\
**Category:** flash\
**Created:** [March 18, 2008, 9:39am UTC](https://forum.kirupa.com/t/is-there-a-way-to-create-an-object-based-on-a-string-value/255016 "2008-03-18T09:39:42Z")\
**Posts on this page:** 1\
**Page:** 1

<div class="post-metadata">

**Author:** ![grandpaw\_broon](https://yyz1.discourse-cdn.com/flex011/user_avatar/forum.kirupa.com/grandpaw_broon/32/3985_2.png) [@grandpaw\_broon](https://forum.kirupa.com/u/grandpaw_broon)\
**Post date:** [March 18, 2008, 9:39am UTC](https://forum.kirupa.com/t/is-there-a-way-to-create-an-object-based-on-a-string-value/255016/1 "2008-03-18T09:39:42Z")

</div>

[LEFT]  
Hi people!

I have a set of buttons that dispatch an event when clicked on. One thing im kind of struggling with is to create a new object based on button clicked.

If i click on contact us, i need to load up the contact us module. However im not really sure how to do this without hard coding the values.

an example of hard coding the issue i mean:

private var menuArray:Array = (“option1”, “option2”, option3");

… on the buttons when clicked i dispatch a custom event

private function onClick(c:CustomEvent): Void  
{  
switch (c.id);  
case 0:  
currentSection = new Option1();  
break;  
// and so on and so forth

}

Is there a better way to go about this?

Thanks 😃

[/LEFT]
