1

In my class, if I create bitmapData like this:

private var tImage:BitmapData;


public function object():void {
        tImage = new BitmapData(30,30,false,0x000000);
}

I get the following error:

ArgumentError: Error #2015: Invalid BitmapData.

But if I declare the variable inside the method:

public function object():void {
    var tImage:BitmapData;
    tImage = new BitmapData(30,30,false,0x000000);
}

It works fine. WHY!?!?! It's driving me crazy.

Thanks guys!

numerical25
  • 10,524
  • 36
  • 130
  • 209
  • 1
    I'd say there is something else going on here, the bug may not be in the code you are sharing. What is this sitting within, can you share more of the bigger picture? – Tyler Egeto Dec 31 '09 at 18:59

2 Answers2

0

I think it might be some other code in your class.

The following works, but I didn't name the function "object" (since I'm guessing that's a reserved word??)

package
{
/**
* ...
* @author your name here
*/
  import flash.display.MovieClip;
  import flash.events.Event;
  import flash.display.Bitmap;

  public class TestBitmap extends MovieClip
  {

    private var tImage:BitmapData;

    public function TestBitmap():void
    {
      if (stage) init();
      else addEventListener(Event.ADDED_TO_STAGE, init);
    }

    private function init(e:Event = null):void 
    {
            tImage = new BitmapData(30,30,false,0x000000);
    }
  }
}

This simplified version below also works too:

package
{
/**
* ...
* @author your name here
*/
  import flash.display.MovieClip;
  import flash.events.Event;
  import flash.display.Bitmap;

  public class TestBitmap extends MovieClip
  {

    private var tImage:BitmapData;

    public function TestBitmap():void
    {
     tImage = new BitmapData(30,30,false,0x000000);
    }


  }
}
redconservatory
  • 21,438
  • 40
  • 120
  • 189
-1

You declared tImage as private...

private var tImage:BitmapData;


public function object():void {
        tImage = new BitmapData(30,30,false,0x000000);
}

Its should be

var tImage:BitmapData;


public function object():void {
        tImage = new BitmapData(30,30,false,0x000000);
}

Derp