# Can you reference a variable by string concatenation?

**URL:** <https://forum.kirupa.com/t/can-you-reference-a-variable-by-string-concatenation/319051>\
**Category:** Uncategorized\
**Created:** [February 7, 2011, 7:16pm UTC](https://forum.kirupa.com/t/can-you-reference-a-variable-by-string-concatenation/319051 "2011-02-07T19:16:46Z")\
**Posts on this page:** 1\
**Page:** 1

<div class="post-metadata">

**Author:** ![jdsflash](https://avatars.discourse-cdn.com/v4/letter/j/3ec8ea/32.png) [@jdsflash](https://forum.kirupa.com/u/jdsflash)\
**Post date:** [February 7, 2011, 7:16pm UTC](https://forum.kirupa.com/t/can-you-reference-a-variable-by-string-concatenation/319051/1 "2011-02-07T19:16:46Z")

</div>

I want to reuse these two functions for about 10 items that need to be dragged and dropped.  
I need to reference 10 Boolean variables on the main timeline by building strings in the functions to make up the Boolean names so I can reuse the functions.  
Am I making since? Check the coded in red.  
[www.dev.wisc-online.com/prototypes/DD.zip](http://www.dev.wisc-online.com/prototypes/DD.zip)  
Fla is above  
[AS]  
stop()  
var startX:Number;  
var startY:Number;  
var counter:Number = 0;  
hip\_mc.addEventListener(MouseEvent.MOUSE\_DOWN, pickUp);  
hip\_mc.addEventListener(MouseEvent.MOUSE\_UP, dropIt);  
function pickUp(event:MouseEvent):void {  
event.target.startDrag(true);  
reply\_txt.text = “”;  
event.target.parent.addChild(event.target);  
startX = event.target.x;  
startY = event.target.y;  
}  
function dropIt(event:MouseEvent):void {  
event.target.stopDrag();  
var myTargetName:String = “target” + event.target.name;  
var myTarget:DisplayObject = getChildByName(myTargetName);  
if (event.target.dropTarget != null && event.target.dropTarget.parent == myTarget){  
reply\_txt.text = “Good Job!”;  
event.target.removeEventListener(MouseEvent.MOUSE\_DOWN, pickUp);  
event.target.removeEventListener(MouseEvent.MOUSE\_UP, dropIt);  
event.target.buttonMode = false;  
[//event.target.x](https://event.target.x) = myTarget.x;  
[//event.target.y](https://event.target.y) = myTarget.y;  
this[event.target.name].visible = false  
this[“target”+ event.target.name].alpha = 100;

this[“Dp”+ event.target.name] = true  
[COLOR=“red”]  
//DpHip\_mc is a boolean variable not a MC  
//need to make this code below dynamic not hard coded  
MovieClip(root).DpHip\_mc = this[“Dp”+ event.target.name]  
//how would i refrence this variable like this…  
MovieClip(root)[“Dp”+ event.target.name] = this[“Dp”+ event.target.name]  
// event.target.name = DpHip\_mc

[/COLOR]  
counter++;  
} else {  
reply\_txt.text = “Try Again!”;  
event.target.x = startX;  
event.target.y = startY;  
}  
if(counter == 4){  
reply\_txt.text = “Congrats, you’re finished!”;  
}  
}

[/AS]
