# Reference dynamic elements by name

**URL:** <https://forum.kirupa.com/t/reference-dynamic-elements-by-name/280177>\
**Category:** Uncategorized\
**Created:** [January 23, 2009, 7:10pm UTC](https://forum.kirupa.com/t/reference-dynamic-elements-by-name/280177 "2009-01-23T19:10:57Z")\
**Posts on this page:** 1\
**Page:** 1

<div class="post-metadata">

**Author:** ![Fhrosty](https://avatars.discourse-cdn.com/v4/letter/f/e480ec/32.png) [@Fhrosty](https://forum.kirupa.com/u/Fhrosty)\
**Post date:** [January 23, 2009, 7:10pm UTC](https://forum.kirupa.com/t/reference-dynamic-elements-by-name/280177/1 "2009-01-23T19:10:57Z")

</div>

getChildByName(“name”) works great if my object has been added to the stage or some MC. But what can I do if I have an object created dynamically that I want to reference later in the code but haven’t added to the stage? Here’s an example:

> 

for (var a = 0; a \< 10; a++) {  
var testObject = addChild(new BlankMC());  
testObject.name = “myTest\_” + a;  
}

// later in the code

var someItem = getChildByName(“myTest\_3”);  
trace(someItem);

This returns my BlankMC instance, but ONLY because it was added to the stage. If I don’t use “addChild”, then I get “null” because my instance is not a child of the stage (or anything else as far as I know). Is getChildByName the ONLY function for referencing a dynamic element?
