# Graphics.clear(); trouble

**URL:** <https://forum.kirupa.com/t/graphics-clear-trouble/323843>\
**Category:** Uncategorized\
**Created:** [July 20, 2011, 8:20pm UTC](https://forum.kirupa.com/t/graphics-clear-trouble/323843 "2011-07-20T20:20:10Z")\
**Posts on this page:** 1\
**Page:** 1

<div class="post-metadata">

**Author:** ![Captain\_Planet](https://avatars.discourse-cdn.com/v4/letter/c/85f322/32.png) [@Captain\_Planet](https://forum.kirupa.com/u/Captain_Planet)\
**Post date:** [July 20, 2011, 8:20pm UTC](https://forum.kirupa.com/t/graphics-clear-trouble/323843/1 "2011-07-20T20:20:10Z")

</div>

Hi,

On frame 2 of my movie clip, if I click a button called DrawLine, it draws a line. Something like this:

var lineholder4:MovieClip = new MovieClip();  
lineholder4.graphics.clear();  
lineholder4.graphics.lineStyle(2, 16711935, 1000);  
addChild(lineholder4);  
lineholder4.graphics.moveTo(…  
lineholder4.graphics.lineTo(…

This part work fine. However, if I click the button to draw the line, and then go back to frame 1 via my navigation buttons, the line is stil there. And I want to clear it. I can clear it using this:

lineholder4.graphics.clear();

But obviously, if I have this on frame 1 before I get to frame 2, the MC wont exist and I’ll get a ‘object null’ error. So I’ve tried EVERYTHING to oversome this…well…everything to my knowledge…but I keep getting errors on the ‘If’ part. Please help! I’ve tried:

if (lineholder4.stage) {  
lineholder4.graphics.clear();  
}

if(stage.contains(lineholder4)){  
lineholder4.graphics.clear();  
}

if (this.getChildByName(lineholder4) == null) {  
lineholder4.graphics.clear();  
}

Is there another way to accomplish this?
