# Dynamically declaring/accessing objects

**URL:** <https://forum.kirupa.com/t/dynamically-declaring-accessing-objects/317053>\
**Category:** flash\
**Created:** [December 9, 2010, 3:23am UTC](https://forum.kirupa.com/t/dynamically-declaring-accessing-objects/317053 "2010-12-09T03:23:09Z")\
**Posts on this page:** 1\
**Page:** 1

<div class="post-metadata">

**Author:** ![fall0utm0dd](https://avatars.discourse-cdn.com/v4/letter/f/3e96dc/32.png) [@fall0utm0dd](https://forum.kirupa.com/u/fall0utm0dd)\
**Post date:** [December 9, 2010, 3:23am UTC](https://forum.kirupa.com/t/dynamically-declaring-accessing-objects/317053/1 "2010-12-09T03:23:09Z")

</div>

So heres my code in my main game loop:

```auto
if (! initialized)
{
	for (var c = 1; c < 1000; c++)
	{
	        var particle:Particle = new Particle();
		particle.name = "particle" + c;
		trace(particle.name);
	}
	initialized = true;
}
particle4.x = 200;
particle4.y = 300;
addChild(particle4);

```

The error given is “1120: Access of undefined property particle4.” However, everything traces correctly, but the individual particles cannot be accessed outside of the loop. Eventually I want to add the next particle at the mouse position on every click, but obviously I can’t do that without being able to access the individual particles. I also read about having to use getChildByName() to access names set in AS3, but I haven’t been able to get that to work either. Help appreciated.
