# Problem with 'getChildBy Name()'

**URL:** <https://forum.kirupa.com/t/problem-with-getchildby-name/269255>\
**Category:** Uncategorized\
**Created:** [August 25, 2008, 12:35pm UTC](https://forum.kirupa.com/t/problem-with-getchildby-name/269255 "2008-08-25T12:35:07Z")\
**Posts on this page:** 1\
**Page:** 1

<div class="post-metadata">

**Author:** ![seanysean](https://avatars.discourse-cdn.com/v4/letter/s/13edae/32.png) [@seanysean](https://forum.kirupa.com/u/seanysean)\
**Post date:** [August 25, 2008, 12:35pm UTC](https://forum.kirupa.com/t/problem-with-getchildby-name/269255/1 "2008-08-25T12:35:07Z")

</div>

Hi,

I’m building something in Papervision3D.

I often get a problem when I try to use ‘getChildByName()’ which throws up this error:

[COLOR=darkslategray]TypeError: Error #1009: Cannot access a property or method of a null object reference.[/COLOR]  
[COLOR=darkslategray]at pages\_test\_72\_fla::MainTimeline/loop()[/COLOR]

Here’s the example which caused this instance.

The code which causes it is inside a [COLOR=darkred]function loop(e:Event):void{}.[/COLOR]

This code works fine:

[COLOR=darkslategray]if(camera.rotationY == -45)[/COLOR]  
[COLOR=darkslategray]{[/COLOR]  
[COLOR=darkslategray]camera.z += zDist \* 0.1;[/COLOR]  
[COLOR=darkslategray]}[/COLOR]

But I have a number of planes in this movie and I want this scroll to suspend when those planes are at certain coordinates. The problem occurs when I add this to my code ([COLOR=#8b0000]planePos [/COLOR][COLOR=black]is a number var I set up earlier[/COLOR])…

[COLOR=darkslategray]if((camera.rotationY == -45) [COLOR=darkred]&& (getChildByName(“plane” + planePos).x \< 500) || (getChildByName(“plane” + (planePos + 10)).x \< 1700)[/COLOR][COLOR=darkslategray])[/COLOR]  
{  
camera.z += zDist \* 0.1;  
}[/COLOR]

The ‘planes’ in question (numbered ‘plane1’ to ‘plane18’) are defined well before my loop occurs using the following code:

[COLOR=darkslategray]var plane1: Plane = new Plane(this.mm1, 350, 260, 2, 2);[/COLOR]  
[COLOR=darkslategray]scene.addChild(plane1);[/COLOR]  
[COLOR=darkslategray]plane1.y = 0;[/COLOR]  
[COLOR=darkslategray]plane1.x = 0;[/COLOR]  
[COLOR=darkslategray]plane1.z = 0;[/COLOR]

Am I just missing something really obvious here? Can anyone see what I’m doing wrong?

Many thanks in advance.

S.
