views:

255

answers:

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 varible inside the method

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

It works fine. WHY!?!?! its driving me crazy.

Thanks guys!

A: 

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