Hi,

I've started writing this class that draws a stripe of random color across the stage within certain parameters. I'm calling an instance of this class and then calling it's newLine() method 25 times in a loop with greater x coords passed in each time, to draw these stripes across the stage.

Sometimes it completely works, no errors, but often it will stop after a seemingly random number of cycles through the loop and give me this error:

ArgumentError: Error #2015: Invalid BitmapData.
at flash.display::BitmapData()
at LineMaker/newLine()
at lineMaker_test_fla::MainTimeline/frame1()

Here's the class code:

PHP Code:
package 
{
    
import flash.display.MovieClip;
import flash.display.Bitmap;
import flash.display.BitmapData;
import flash.display.DisplayObject;
import flash.geom.Rectangle;
    
public class 
LineMaker 
    
{

    private var 
lineCount:Number 0;
    private var 
target_mc:MovieClip;
    private var 
bgWidth:Number;
    private var 
BMPD:BitmapData;
    private var 
BMP:Bitmap;
    
    
//constructor
    
public function LineMaker(target:MovieClipbgWidth:Number)
        {
        
this.target_mc target;
        
this.bgWidth bgWidth;
        }
    
    
//create a bitmap line
    
public function newLine(wMax:Numberh:NumberxInterval:NumberxPos:NumberyPos:Number)
        {
        var 
w:Number Math.random() * wMax;
        var 
xPosition:Number xPos Math.random() * xInterval;
        var 
thisColor:Number getRandomColor();
        
this.BMPD = new BitmapData(whfalsethisColor);
        
this.BMP = new Bitmap(this.BMPD);
        var 
BMPref:DisplayObject this.target_mc.stage.addChildAt(this.BMP0);
        
BMPref.xPos;
        }
    
    private function 
getRandomColor(): Number
        
{
        var 
color:Number Math.random() * 0xFFFFFF;
        return 
color;
        }
    
    }

Can anyone explain why I might be getting this error? I thought it might have something to do with the way I'm getting my random color value, but the error doesn't seem to be at all correlated to the color value at the time of failure...

Many thanks!