# Refering to an Instance Name by Variable

**URL:** <https://forum.kirupa.com/t/refering-to-an-instance-name-by-variable/296185>\
**Category:** Uncategorized\
**Created:** [September 10, 2009, 3:02pm UTC](https://forum.kirupa.com/t/refering-to-an-instance-name-by-variable/296185 "2009-09-10T15:02:45Z")\
**Posts on this page:** 1\
**Page:** 1

<div class="post-metadata">

**Author:** ![bigfoot](https://avatars.discourse-cdn.com/v4/letter/b/b2d939/32.png) [@bigfoot](https://forum.kirupa.com/u/bigfoot)\
**Post date:** [September 10, 2009, 3:02pm UTC](https://forum.kirupa.com/t/refering-to-an-instance-name-by-variable/296185/1 "2009-09-10T15:02:45Z")

</div>

I am trying to create a game in Flash. There are 43 spaces of irregular shape in the game and I already know the X and Y location. I defined them as a class which extends movie clip, I put them on the main timeline to start and I gave them all an instance name. I want to initialize them when I am starting a new game. I defined methods to set and get the properties, those methods work when I use the instance name, but many of the spaces share the same properties. The instance names are all I+some numberm I1, I2, I3. When I try to use a variable name such as space\_Id = (“I” + i) to reference the instance name I get an error "Call to a possibly of undefined method. I tried the old actionscript 2 solution of putting an eval function eval (space\_id) in front of the method but that didn’t work either. It resulted in the same error plus a warning.

I1.My\_Method (); // works but it would require 20 or so blocks of almost identical code

var space\_Id:String = “I1”;  
space\_Id.My\_Method (); // doesn’t work

\_root.space\_Id.My\_Method (); doesn’t work  
eval (space\_Id).My \_Method; doesn’t work

Is there a way to use a variable to reference the instance name of an object that is a user defined class.

Closest I got, I think is using the class name Space

Space.eval (space\_Id).My\_Method ();  
generates Error #1123: Filter operator not supported on type class Space.

Any help would be appreciated.
