我有这段代码可以完美运行,但偶尔——只要 Flash 这么认为——它就会崩溃。这是生成的调试文本:
错误 #2025
显示结果:真
多莉 = 10
多莉补充说
添加了通用芯片
高亮 SH:[object SurfaceElement]10-[object TSprite]-vex!
参数错误:错误 #2025
请注意“烦恼!” 是对象 vex 的名称,它是一个 TSprite (=Sprite)。
public function update(players:Array, showResult:Boolean = false):void {
try {
var debug:String = "showResult:" + showResult.toString() + "\n";
debug += "dolly = " + dolly.toString();
// RESET columns
columns.length = 0;
billboards.removeAllChildren();
var column:ChipColumn;
// add dolly
var alfa:Number = 1;
if (showResult) {
column = getChipColumn(vex.getChildIndex(numberToSH[dolly]));
column.addChild(dollySpr);
alfa = LOSER_ALPHA; // fade-out (non-animated) non-winning columns
}
debug += "\nDolly added";
for (var k:* in players) {
var player:Player = players[k];
var bets:Array = player.getBets();
for (var i:* in bets) {
// is there a column already for these chips?
column = getChipColumn(i);
column.alpha = alfa; // loser..?
for (var j:int = bets[i]; j > 0; --j) {
var bmp:TBitmap = new TBitmap(chips[k], Align.CENTER, Align.CENTER);
bmp.y = - column.numChildren * 5;
column.addChild(bmp);
}
}
}
debug += "\nGeneric Chips added";
if (showResult) {
var shs:Array = SurfaceElement.NumberToAllSH[dolly];
for each (var sh:SurfaceElement in shs) {
debug += "\nHighlighting SH:" + String(sh);
debug += sh.corresponds.toString();
debug += "-" + String(sh.parent);
debug += "-" + String(sh.parent.name);
column = getChipColumn(vex.getChildIndex(sh)); // ERROR LINE ?!?
column.alpha = 1; // restore alpha
column.filters = [new GlowFilter(0xffffff, 1, 12, 12, 3, 3)];
}
}
debug += "\nEnd of Highlighting !!!!!!";
// sort columns by y
var sorted:Array = columns.sortOn("sortY", Array.NUMERIC | Array.RETURNINDEXEDARRAY);
debug += "\n" + sorted.toString();
for (i in sorted) {
column = columns[sorted[i]];
if (!column) break; // pointers to undefined data have arrived (put last)
billboards.addChild(column);
}
debug += "\nEnd of ALL";
} catch(e:Error) {
if (!Debug.field.text.length) {
Debug.field.textColor = 0xffffff;
Debug.field.appendText(e.message + "\n" + debug + "\n" + e.toString());
}
}
}
private function getChipColumn(i:int):ChipColumn {
var column:ChipColumn = columns[i];
if (!column) {
column = new ChipColumn();
// calc column properties
var sh:SurfaceElement = vex.getChildAt(i) as SurfaceElement;
var point:Point = sh.getCenterProjected();
point = billboards.globalToLocal(point);
column.sortY = sh.center.y;
column.x = point.x;
column.y = point.y;
columns[i] = column;
}
return column;
}
从调试文本中,很明显错误发生在这里:
debug += "\nHighlighting SH:" + String(sh);
debug += sh.corresponds.toString();
debug += "-" + String(sh.parent);
debug += "-" + String(sh.parent.name);
column = getChipColumn(vex.getChildIndex(sh)); // ERROR LINE ?!?
为非子对象调用 getChildIndex 时会发生错误 2025。但正如父母的名字所暗示的那样, sh 是 vex 的孩子(vex!)。而且只有一个vex 。
另一个奇怪的事情是错误消息(e.message)只是产生: 错误 2025 而错误到字符串(e.toString())产生: ArgumentError: Error #2025
它不应该说得更像:
ArgumentError:错误 #2025:提供的 DisplayObject 必须是调用者的子对象??