# Accessing a movieclip with string variable as name

**URL:** <https://forum.kirupa.com/t/accessing-a-movieclip-with-string-variable-as-name/269430>\
**Category:** flash\
**Created:** [August 27, 2008, 3:03pm UTC](https://forum.kirupa.com/t/accessing-a-movieclip-with-string-variable-as-name/269430 "2008-08-27T15:03:41Z")\
**Posts on this page:** 1\
**Page:** 1

<div class="post-metadata">

**Author:** ![noverflow](https://avatars.discourse-cdn.com/v4/letter/n/e56c9b/32.png) [@noverflow](https://forum.kirupa.com/u/noverflow)\
**Post date:** [August 27, 2008, 3:03pm UTC](https://forum.kirupa.com/t/accessing-a-movieclip-with-string-variable-as-name/269430/1 "2008-08-27T15:03:41Z")

</div>

I have a button called px (p1 - p8). When you press it I want to call a function that returns the x position of globalWrapper.px (p1 - p8) (different movieClips).

So I tried:

```php

p1.addEventListener(MouseEvent.MOUSE_UP, buttonMouseUp);
...
p8.addEventListener(MouseEvent.MOUSE_UP, buttonMouseUp);

function buttonMouseUp(event:MouseEvent):void{
	var targetP:String = 'globalWrapper.'+event.target.name;
	var end:MovieClip = targetP;
	
	trace(end.x);
	
}

```

But obviously this does not work as I am trying to change the variable type.  
Anyone know how to do this correctly?
