views:

120

answers:

1

The title might be a little misleading. Look at my code and I will explain

public static function loadTile(tileDir:String = "empty"):void
        {
            if(tileDir != "empty")
            {
                tPoint = new Point(0,0);
                tRect = new Rectangle(0,0,30,30);

                //load in tile sheet image
                loader = new Loader();
                loader.contentLoaderInfo.addEventListener(Event.INIT,tilesLoadInit);
                loader.load(new URLRequest(tileDir));
            }
        }

         private static function tilesLoadInit (e:Event):void {
             tileImage = Bitmap(loader.content).bitmapData;
             tileReady.dispatchEvent(new Event("TileReady"));
         }
var tImage:BitmapData = new BitmapData(30,30);
tileNum = tileNumber;
tPoint.x = 0;
tPoint.y = 0;

tRect.x = 0;
tRect.y = 0;

tImage.copyPixels(tileImage,tRect,tPoint);

this.graphics.beginBitmapFill(tImage);
this.graphics.drawRect(0, 0,tWidth ,tHeight );

I create a empty bitMapData called tImage. I then take a predefined variable called tileImage which is a bitMapData as well and contains a picture of an image. tRect is predefined as well its width and height is 30x30. I copy a piece of the image and I put it in tImage. problem is that AS3 throws an error saying that tImage is a incorrect type

ArgumentError: Error #2015: Invalid BitmapData.

But clearly it isnt. my question is that is there something different about the data type of bitMapData and bitMapData type that the graphic object accepts ?

I am trying to do tiling with sprites. I want my tiles to be interactive, so that is why I am using the sprite object instead of using regular bitMaps to represent my tiles. You might be wondering why I wouldnt just use graphics.beginBitmapFill(tImage); and graphics.drawRect(0, 0,tWidth ,tHeight ); to pick out the tiles I want to use. Well reason being is because it turns out that drawRect() first and second parameters actually alter the location of where the actual sprite sits at.

So if I set the x and y properties of the sprite to x = 20, and y = 20. then I set my drawRect(20,20). it actually adds an extra 20 pixels to my x and y coords of my sprite. And I know the reason why, I just need to know a better way. Sorry for so much writing and thanks for your time!

A: 

It's not saying the type is wrong, it's saying the object is invalid. I expect you'd get a TypeError if the type was wrong.

You've also not stated where exactly the error is thrown, and are assuming the problem is with tImage on the 8th line. It looks more likely that the problem is with tileImage (which you've given no details about) on line 7.

Kylotan
I added more detail on tileImage. Like I said before, its a bitMapData, And it works. If I pass tileImage in the beginBitmapFill method instead of tImage. it works and I recieve no errors. but if instead I try to crop the image first and then pass it in, thats when the error above occurs. They are both bitMapdatas types, except when I decide to crop the image first using the copyPixel method, it doesnt work.
numerical25
Sorry if I cant be as detailed. But in a nutshell, any bitMapData that gets it content from a copypixel method, doesnt work within a beginBitmapFill method. Its still a bitMapData type, yet it doesnt work. Im just curious on why
numerical25