English 中文(简体)
AS3 - 指数范围不一(1125)
原标题:AS3 - The index is out of range (Error #1125 )

http://www.gotoandletain.com/ files/tabletswipe.zip” tral=“nofflow”

范围 指数在幅度之内。

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

造成错误的原因是什么?

问题回答
canvas.copyPixels(photos[ind], rect, zp);

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

Do checks on ind and ind+1 to make sure they re less than photos.length





相关问题
Attaching a property to an event in Flex/AS3

I have a parameter that needs to be passed along with an event. After unsuccessful attempts to place it on the type by extending the class, I ve been advised in another SO question to write a custom ...

Sorting twodimensional Array in AS3

So, i have a two-dimensional Array of ID s and vote count - voteArray[i][0] = ID, voteArray[i][1] = vote count I want the top 3 voted items to be displayed in different colors, so i have a 2nd Array -...

Virtual Tour using sketch up, ajax, flash technologies

I want to know if there are existing technology that make your 3d models in sketch into virtual tours, using either Ajax or Flash for web presentation. If there s none, which will be a good approach ...

What s a good way of deserializing data into mock objects?

I m writing a mock backend service for my flex application. Because I will likely need to add/edit/modify the mock data over time, I d prefer not to generate the data in code like this: var mockData =...

AS3 try/catch out of memory

I m loading a few huge images on my flex/as3 app, but I can t manage to catch the error when the flash player runs out of memory. Here is the what I was thinking might work (I use ???? because i dont ...

热门标签