# Problem using getChildByName in Scrollpane

**URL:** <https://forum.kirupa.com/t/problem-using-getchildbyname-in-scrollpane/317439>\
**Category:** flash\
**Created:** [December 20, 2010, 6:10pm UTC](https://forum.kirupa.com/t/problem-using-getchildbyname-in-scrollpane/317439 "2010-12-20T18:10:22Z")\
**Posts on this page:** 1\
**Page:** 1

<div class="post-metadata">

**Author:** ![leeda111](https://avatars.discourse-cdn.com/v4/letter/l/b9bd4f/32.png) [@leeda111](https://forum.kirupa.com/u/leeda111)\
**Post date:** [December 20, 2010, 6:10pm UTC](https://forum.kirupa.com/t/problem-using-getchildbyname-in-scrollpane/317439/1 "2010-12-20T18:10:22Z")

</div>

Hi,

This problem was discussed a couple days earlier as well but it was not resolved. and after wasting tow more days I still have no clue and banging my head in the wall. Alright, Here is the question first before I start describing in detail:

Why this code is working

```auto
if(event.target.hitTestObject(testMC.myBorder1))
{}

```

While this code is not working(it works only for myBorder1)

```auto
for(var i:int=1;i<=6;i++){
		var abcd:String="myBorder"+i;
		trace(abcd);
		if(event.target.hitTestObject(testMC.getChildByName(abcd))){}}

```

I have tried many ways and figured this was working too

```auto
var check1:String="myBorder1"; if(event.target.hitTestObject(Object(sp.content).getChildByName(check1)))

```

But the corresponding code is not working for any other myBorder except myBorder1

```auto
for(var i:int=1;i<=6;i++){
		var abcd:String="myBorder"+i; if(event.target.hitTestObject(Object(sp.content).getChildByName(abcd))){}}

```

======================================  
Here are the details

The stage is empty  
the code where I am creating the scrollpane

```auto
var sp:ScrollPane = new ScrollPane();
sp.move(10,10);
sp.setSize(400,150);
sp.source = panedata;
sp.scrollDrag = true;
addChild(sp);

```

Inside the scrollpane there is a panedata movieclip which has 6 instances of myBorder namely myBorder1,myBorder2…myBorder6

Then I create 2 instaces of a movieclip and add ONE of them to stage and add eventlisteners to it

```auto
var F22o:F22 = new F22();
var F22mc:F22 = new F22();
addChild(F22o);
F22o.x=451;
F22o.y=308;
 
F22o.addEventListener(MouseEvent.MOUSE_DOWN, startdrag);
F22o.addEventListener(MouseEvent.MOUSE_UP, stopdrag);

```

Start Drag Function

```auto
function startdrag(event:MouseEvent):void {
	event.target.startDrag(true);
	
	startX = event.target.x;
	startY = event.target.y;
	
	
	
}

```

Here is the stopdrag function

```auto
function stopdrag(event:MouseEvent):void {
	
	event.target.stopDrag();
 testMC = sp.content as MovieClip;
	
		[COLOR="Red"]**Code: Here is should check with all the myBorder's if there is any hit and place it on the specific myBorder or throw the mc back to irs original position(incase there was no hit)**[/COLOR]
}

```

Lemme know if there is any other info needed.

Here images \*\*\* well  
Image of stage and library  
 ![](http://forum.kirupa.com/uploads/kirupa/6424/02619462a1cd1644.png)

Image of panedata(named myBorder1,myBorder2,myBorder3,myBorder4,myBorder5,myBorder6)  
 ![](http://forum.kirupa.com/uploads/kirupa/6425/a6a23c08f469cd58.png)

Here I uploaded the swf:  
[http://www.swfupload.com/view/142693.htm](http://www.swfupload.com/view/142693.htm)  
[http://megaswf.com/serve/87256/](http://megaswf.com/serve/87256/)  
In the uploaded, swf’s it only works for myBorder1

Here is the previous thread we discussed this matter in:  
[http://www.kirupa.com/forum/showthread.php?t=358374](http://www.kirupa.com/forum/showthread.php?t=358374)

Thanks in advance
