2012-05-11 64 views
0

downloadedtutorial文件,並通過測試它,我得到這個錯誤:AS3 - 該指數超出範圍(錯誤#1125)

RangeError: Error #1125 The index is out of range

// 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(); 
     }); 

是什麼原因造成的錯誤?

回答

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

或者

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

請在IND和IND + 1檢查,以確保他們不到photos.length