A Flash Developer Resource Site

Results 1 to 4 of 4

Thread: problem with BitmapData

  1. #1
    flip-flopper scottPadgett's Avatar
    Join Date
    Jan 2005
    Location
    Boston
    Posts
    425

    problem with BitmapData

    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!
    :: scott ::

  2. #2
    Senior Member
    Join Date
    Jan 2008
    Posts
    150
    Maybe w is sometimes too small for it to handle appropriately?

  3. #3
    flip-flopper scottPadgett's Avatar
    Join Date
    Jan 2005
    Location
    Boston
    Posts
    425
    I though about that, but I trace the value that it fails on, and sometimes the value is low, sometimes high, but well within the range of what often simply works. I also thought maybe it didn't like a decimal value as color value so I added a round() call around the number and that still changes nothing.

    Oh, wait, you said w. That I haven't addressed. Maybe you are right, I'll write in a lower limit and see what happens. You may well be right.
    :: scott ::

  4. #4
    flip-flopper scottPadgett's Avatar
    Join Date
    Jan 2005
    Location
    Boston
    Posts
    425
    Awesome! You're exactly right. It can't deal with a BitmapData object less than 1px in width.

    Thanks a bunch.
    :: scott ::

Posting Permissions

  • You may not post new threads
  • You may not post replies
  • You may not post attachments
  • You may not edit your posts
  •  




Click Here to Expand Forum to Full Width

HTML5 Development Center