2011-09-10 130 views
0

我有以下问题:我有这个多级数组(嵌套数组),其中包含两行bitmapData。第1行:360位旋转的bitmapData对象;第2行:360旋转和彩色的bitmapData对象。嵌套数组不工作

我尝试访问第2行,但不起作用。有一些神秘的错误消息(“TypeError:Error#1034:Type Coercion failed:can not [] @ 36d7e9e9 to flash.display.BitmapData。at BasicBlitArrayObject/updateFrame()”)。

请问有人可以帮我解决这个问题吗?非常感谢你。

此函数旋转并着色bitmapData;旋转后的bitmapData被抛入一个数组中,彩色的bitmapData被抛入另一个数组中;第三阵列用作级阵列中嵌套它

public function  createColoredRotationBlitArrayFromBD(sourceBitmapData:BitmapData, inc:int,  offset:int = 0, color:Number = 1, $alpha:Number = 1):Array 
{ 

tileList = []; 
tileListSec = []; 
levelArray = [tileList, tileListSec]; 
var rotation:int = offset; 

while (rotation < (360 + offset)) 
{ 
    var angleInRadians:Number = Math.PI * 2 * (rotation/360); 
    var rotationMatrix:Matrix = new Matrix(); 

    rotationMatrix.translate(-sourceBitmapData.width * .5, -sourceBitmapData.height * .5); 
    rotationMatrix.rotate(angleInRadians); 
    rotationMatrix.translate(sourceBitmapData.width * .5, sourceBitmapData.height * .5); 


    var matrixImage:BitmapData = new BitmapData(sourceBitmapData.width, sourceBitmapData.height, 
           true, 0x00000000); 

    matrixImage.draw(sourceBitmapData, rotationMatrix); 
    tileList.push(matrixImage.clone()); 


    bitmapData = new BitmapData(matrixImage.width, matrixImage.height, true, 0x00000000); 
    bitmapData = matrixImage; 


    var colorMatrix:ColorMatrixFilter = new ColorMatrixFilter (
         [color, 0, 0, 0, 0, 
         0, 0, 0, 0, 0, 
         0, 0, 0, 0, 0, 
         0, 0, 0, $alpha, 0]); 

    matrixImage.applyFilter(bitmapData, bitmapData.rect, point0, colorMatrix); 


    tileListSec.push(matrixImage.clone()); 


    rotation += inc; 

    matrixImage.dispose(); 
    matrixImage = null; 
    rotationMatrix = null; 
    bitmapData.dispose(); 
    bitmapData = null; 
    colorMatrix = null; 
    } 

return(levelArray); 

} 

创建我的旋转和有色位图数据

animationFrames = tempBlitArrayAsset.createRotationBlitArrayFromBD($bitmapData, 1, 270); 

这里的其他两个数组我尝试访问我的水平阵列的第一行(即不工作;我不能访问它)

tempEnemy.animationList = animationFrames; 
tempEnemy.bitmapData = tempEnemy.animationList[1][tempEnemy.frame]; 

该功能是用于更新帧

public function updateFrame(inc:int, row:int = 0):void 
{ 
frame += inc; 

if (frame > animationList.length - 1){ 
    frame = 0; 
} 
bitmapData = animationList[row][frame];     


} 

} 

这是显示updateFrame功能是如何在我的游戏中使用的线路(trueRotation为0)

tempEnemy.updateFrame(tempEnemy.trueRotation); 
+0

它看起来像一个数组越来越推到你期望的位图数据。您是否尝试过使用强类型向量而不是数组。如果你知道它总是会有bitmapdatas,那么它是有道理的,当你在那里放置一些没有意义的东西时它会抛出一个运行时异常。我会在后面更详细地看代码,看看我是否能够确切地知道它发生在哪里 –

+0

不,我还没有尝试过一个向量。我个人认为这不是问题。尽管如此,我会稍后再尝试... – drpelz

回答

1

我找不到什么毛病createColoredRotationBlitArrayFromBD

var $bitmapData:BitmapData = new BitmapData(40,40,false, 0x7f7f7f); 
var animationFrames:Array = createColoredRotationBlitArrayFromBD($bitmapData, 1, 270); 
trace(animationFrames.length); // 2 
trace(animationFrames[0].length); // 360 
trace(animationFrames[1].length); // 360 

var bitmap:Bitmap = new Bitmap(); 
this.addChild(bitmap); 
bitmap.bitmapData = animationFrames[1][0]; // works.. 

这似乎正确。对?我得到一个红色的有点位图。

唯一的 '错误' 我在你列出的代码看到的是updateFrame

if (frame > animationList.length - 1){ 
    frame = 0; 
} 

也许应该是:

if (frame > animationList[row].length - 1){ 
    frame = 0; 
} 

因为animationList.length == 2

,但一切看起来不错的你提供的代码,所以没有更多的代码,我不确定是否有任何帮助。

+0

正是!那是错误。我2天前发现了这个bug,现在工作正常。感谢您的提示!:) – drpelz

+0

更改此行“if(frame> animationList.length - 1){”to this“if(frame> animationList [row] .length - 1){ ”。 – drpelz