无效的BitMapdata错误#2015

时间:2009-12-31 00:28:11

标签: actionscript-3 bitmap sprite bitmapdata

        private static var tileDir:String;
        public static var tileImage:BitmapData;
        private static var loader:Loader;

        public static var tileReady:EventDispatcher = new EventDispatcher();
        public static var tileNum_perRow:Number = 3;
        public static var select:selector;

        public var tileNum:Number = 0;
        public var setBack:Number = 0;
        public var tileState:String;
        public var tCol:Number;
        public var tRow:Number;

        private var tWidth:int = 30;
        private var tHeight:int = 30;
        private var tImage:BitmapData;
        private var canvas:Bitmap;

        private var p:Point;
        private var r:Rectangle;    

        public function Tile():void
        {
            var tempImage:BitmapData = tileImage;
            r = new Rectangle(0,0,30,30);
            p = new Point(0,0);
            tImage = new BitmapData(30,30);
            tImage.copyPixels(tempImage,r,p);
        }

我收到以下错误:

ArgumentError: Error #2015: Invalid BitmapData.

复制像素时会发生这种情况。我不知道为什么。

tileImage;

tileImage是有效的,我在下面的代码中使用了变量并且它有效。但上面没有。不知道为什么。有人有任何线索吗?

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

1 个答案:

答案 0 :(得分:0)

没关系,我想出更好的解决方案

                theMatrix.translate(30,0);
        this.graphics.beginBitmapFill(tileImage,theMatrix);
        //this.graphics.drawRect(0, 0,tWidth ,tHeight );
        this.graphics.endFill();

使用theMatrix.translates,您可以选择所需的图块部分,而不会影响精灵的位置