setPixels, getPixels, Flash Genius needed!

Hi,
I am trying to do real time background subtraction with my webcam by comparing two bytearrays and using the getPixels and setPixels methods.
I basically want to colour the resulting image one colour if the pixels from the first and second images match, and another if they are different.
I have achieved this in very simple terms in the getpixelspic file attached.
The problems happens when I try to do this in real time using a repeating function inside an .as file to repeatedly compare the webcam stream to a still image taken by an mouse click event listener function, as I have tried to do in the attached .as file.

the .fla file you will need to use in conjunction to the attached .as file is:

import mymotioncamSubtractarray;
var newParticle - new mymotioncamSubtractarray();
addChild(newParticle);
stage.addEventListener(MouseEvent.CLICK, newParticle.takepic);

For some reason I keep getting the error "cannot access a property or method of a null object reference, which is coming from the looped function render().
Please help if you can. Don’t be annoyed by the excessive commenting, I needed to send it to my teacher.
Thanks,
Naomi