# If statement does not work

**URL:** <https://forum.kirupa.com/t/if-statement-does-not-work/317817>\
**Category:** flash\
**Created:** [January 4, 2011, 12:34am UTC](https://forum.kirupa.com/t/if-statement-does-not-work/317817 "2011-01-04T00:34:02Z")\
**Posts on this page:** 1\
**Page:** 1

<div class="post-metadata">

**Author:** ![rimacy](https://avatars.discourse-cdn.com/v4/letter/r/839c29/32.png) [@rimacy](https://forum.kirupa.com/u/rimacy)\
**Post date:** [January 4, 2011, 12:34am UTC](https://forum.kirupa.com/t/if-statement-does-not-work/317817/1 "2011-01-04T00:34:02Z")

</div>

the problem is that for some reason my if statement doesn’t work

```auto
if( key.isDown( Keyboard.UP ) ) 
                                {
                                        ship.thrust-=.02;
                                     ship.gravity=-.050;
                                     trace("up");
                                     if(shipLanded=true)
                                     {
                                    
                                         removeChildFunc();
                                     }
                                    
                                      
                                }

```

once the up key is pressed the button is to be removed IF shipLanded is true. so it should just bypass removeChildFunc.

after the above code i have

```auto
 ship.moveShip();
                ship.rotateShip();
                moveRocks();
                land();
               [U]**trace("shipLanded= " + shipLanded );**[/U]
                 healthBar.subtractHealth(ship.damageAmt);
                 checkDeath();
                ship.damageAmt=0;

```

then way down at the bottom i have my removeChildFunc()

```auto
public function removeChildFunc():void
            {
                trace("removing child");
                trace(asBaseScreenButton.parent);
                removeChild(asBaseScreenButton);
            }

```

and here’s my output

shipLanded= true  
shipLanded= true  
shipLanded= true  
up  
removing child  
[object PlayScreen]  
shipLanded= false  
up  
removing child  
null  
ArgumentError: Error #2025: The supplied DisplayObject must be a child of the caller.  
at flash.display::DisplayObjectContainer/removeChild()  
at PlayScreen/removeChildFunc()[C:\Documents and Settings\rob\Desktop\AS3\Projects\AsteroidSupply\Classes\PlayScreen.as:457]  
at PlayScreen/upDate()[C:\Documents and Settings\rob\Desktop\AS3\Projects\AsteroidSupply\Classes\PlayScreen.as:162]

that shipLanded =false should preclude the removing child and the null and the error???
