# Using a variable String as an instance name

**URL:** https://forum.kirupa.com/t/using-a-variable-string-as-an-instance-name/207722
**Category:** flash
**Created:** [November 20, 2006, 11:01pm UTC](https://forum.kirupa.com/t/using-a-variable-string-as-an-instance-name/207722 "2006-11-20T23:01:47Z")
**Posts on this page:** 1
**Page:** 1

<div class="post-metadata">

### Author: ![ZumoWrestler](https://avatars.discourse-cdn.com/v4/letter/z/f05b48/32.png) [@ZumoWrestler](https://forum.kirupa.com/u/ZumoWrestler)
#### Post date: [November 20, 2006, 11:01pm UTC](https://forum.kirupa.com/t/using-a-variable-string-as-an-instance-name/207722/1 "2006-11-20T23:01:47Z")

</div>

Hey Everyone,

I’m making a map and when you hover over a state it has a pop up with some information, pretty easy stuff. Well, I’m using this as my code(HoverCaption Tutorial)…

```auto
 
Missouri.onRollOver = function() {
captionFN(true, this._name + "
 Carriers: " + ranString[numState] + 
"
 Total of " + ranCount[numState] + " Carriers.", this);
this.onRollOut = function() {
captionFN(false);
};
};

```

What I’d like to do is instead of having to make this for every state just pass in the instance name which is the name of the state. I thought my code would look something like this.

for button…

```auto
 
on (rollOver){
var numState:Number = 25;
var strState:String = this._name;
}

```

for other code…

```auto
 
strState.onRollOver = function() {
captionFN(true, this._name + "
 Carriers: " + ranString[numState] + 
"
 Total of " + ranCount[numState] + " Carriers.", this);
this.onRollOut = function() {
captionFN(false);
};
};

```

Well, that doesn’t work, I didn’t know if there is a way to do that, maybe threw a method. Thanks for the help!
