0

下载了这个教程文件并通过测试我得到了这个错误:

RangeError:错误 #1125 索引超出范围

    // MAIN BLIT CANVAS
var canvas:BitmapData = new BitmapData(1024, 768, false);
addChild(new Bitmap(canvas));
addChild(sl);

// PROPERTIES
var ind:int;
var offset:int;
var rect:Rectangle;
var zp:Point = new Point();
var destX:int = 0;
var currentX:int = 0;

// LOAD PHOTOS FROM LIBRARY
var photos:Vector.<BitmapData> = new Vector.<BitmapData>();
for(var i:int=1; i<5; i++)
{
    var ref:Class = getDefinitionByName("p"+i) as Class;
    photos.push(new ref());
}

// LOAD BITMAPDATA INTO MEMORY
for(i=0; i<4;i++)
    canvas.copyPixels(photos[i], new Rectangle(0,0,1,1), zp);

// FIGURE OUT POSITION OF SLIDER AND CALL RENDER
stage.addEventListener(Event.ENTER_FRAME, function(e:Event):void {
                     destX = Math.ceil((sl.thumb.x/908) * 13312);
                     currentX += (destX - currentX) * 0.15;
                     render();
                       });

// RENDER PIXELS TO CANVAS
function render():void
{
    ind = currentX / 1024;
    offset = currentX % 1024;
    rect = new Rectangle(offset, 0, 1024-offset, 768);
    canvas.copyPixels(photos[ind], rect, zp);
    if(currentX < 13312)
        canvas.copyPixels(photos[ind+1], canvas.rect, new Point(1024-offset, 0));
}

//START DRAGGING SLIDER
sl.thumb.addEventListener(MouseEvent.MOUSE_DOWN, function(e:MouseEvent):void {
      sl.thumb.startDrag(false, new Rectangle(0, 0, 909, 0));
      });

//START DRAGGING SLIDER
stage.addEventListener(MouseEvent.MOUSE_UP, function(e:MouseEvent):void {
      sl.thumb.stopDrag();
      });

是什么导致错误?

4

1 回答 1

2
canvas.copyPixels(photos[ind], rect, zp);

或者

canvas.copyPixels(photos[ind+1], canvas.rect, new Point(1024-offset, 0));

检查 ind 和 ind+1 以确保它们小于 photos.length

于 2012-05-11T18:57:09.310 回答