# Class using a loop to target mc's on stage

**URL:** https://forum.kirupa.com/t/class-using-a-loop-to-target-mcs-on-stage/314836
**Category:** flash
**Created:** [October 10, 2010, 2:08am UTC](https://forum.kirupa.com/t/class-using-a-loop-to-target-mcs-on-stage/314836 "2010-10-10T02:08:37Z")
**Posts on this page:** 1
**Page:** 1

<div class="post-metadata">

### Author: ![ggalan](https://avatars.discourse-cdn.com/v4/letter/g/8c91f0/32.png) [@ggalan](https://forum.kirupa.com/u/ggalan)
#### Post date: [October 10, 2010, 2:08am UTC](https://forum.kirupa.com/t/class-using-a-loop-to-target-mcs-on-stage/314836/1 "2010-10-10T02:08:37Z")

</div>

ive been wrestling with this for the whole day, if anyone can lend a hand  
i have 3 check box’s and input text fields on stage that i would like to null out using the reset button  
however i seem to be targeting the objects incorrectly as i am getting this error:

> Error #1009: Cannot access a property or method of a null object reference.

```auto

package
{ 
    import flash.display.*;
    import flash.events.MouseEvent;
	import flash.events.Event;
    import flash.text.TextField

    public class Main extends MovieClip
    {
		private var aCheckBox:Array;
		private var aTextInput:Array;
		
        public function Main():void
		{
            init();
        }
		
        private function init():void 
		{
			bReset.buttonMode = true;
			bReset.addEventListener(MouseEvent.CLICK, resetHandler, false, 0, true);
		}
		
		private function resetHandler(e:MouseEvent):void 
		{
			aCheckBox = [];
			var cb:MovieClip;
			for(var i:int=0;i < 3; i++)	
			{
				cb = getChildByName("cb" + (i + 1)) as MovieClip;
				aCheckBox.push(cb);
				aCheckBox*.selected = false;
			}
			
			aTextInput = [];
			var ti:MovieClip;
			for(var j:int=0;j < 3; j++)
			{
				ti = getChildByName("ti" + (j + 1)) as MovieClip;
				aTextInput.push(ti);
				aTextInput[j].text = "";
			}
			
		}
    }
}

```
