actionscript-3 - 为什么 object.name 中的这些更改会导致不同的显示?
问题描述
我正在做一些简单的事情 - 绘制一系列瓷砖,将它们放在库中并在属性中链接,并创建一个随机选择的瓷砖大矩形。我还希望能够独立访问每个图块,因此我为每个图块使用了数组类型的命名系统。然后我遇到了这种情况,如果我使用变量彼此相邻的命名方案(而不是拆分他们用字符串文字)。
有人可以解释为什么: floor.name = "floorR"+String(n)+"C"+String(m); //行为正常,如预期的那样
给出不同的显示结果: floor.name = "floorRC"+String(n)+String(m); //转换为下面代码中的注释,往往会放错瓷砖
在以下最低限度的、可重复的提取物中:
//initialize standard counters
var i:uint = 0;
var j:uint = 0;
var m:uint = 0;
var n:uint = 0;
var lvlAdd:uint = 0; //designates add level (display)
//starting location of tiles
var bigMapX0:uint = 15;
var bigMapY0:uint = 75;
//dimensions of completed tile set
var bigMapWidth:uint = 375;
var bigMapHeight:uint = 675;
//initialize max row and column
var rowMax = 25;
var columnMax = 15;
//initialize unit-cell dimensions
var cellWidth = bigMapWidth/columnMax;
var cellHeight = bigMapHeight/rowMax;
//backdrop rectangle: black
var backFieldColor = 0x000000;
var backField:Shape = new Shape();
backField.graphics.beginFill(backFieldColor);
backField.graphics.drawRect(bigMapX0,bigMapY0,bigMapWidth,bigMapHeight); //dimensions of standard stage
backField.graphics.endFill();
this.addChildAt(backField,lvlAdd); //sets black as bottommost static backdrop
//set down tiles
var floor:DisplayObject;
var floorName:DisplayObject;
for (m=0; m<columnMax; m++) {
for (n=0; n<rowMax; n++){
floor = new Floor0(); //"floor" is in the library with linkage named Floor0 (part of an assortment of tiles randomly chosen, and not shown here to reduce lines of code
//floor.name = "floorR"+String(n)+"C"+String(m);
floor.name = "floorRC"+String(n)+String(m); //error happens if this line is used instead of the commented line above it
lvlAdd++;
this.addChildAt(floor, lvlAdd);
//floorName = this.getChildByName("floorR"+String(n)+"C"+String(m));
floorName = this.getChildByName("floorRC"+String(n)+String(m)); //this is the paired statement with the floor.name 3 lines prior, and causes an error in display if used instead of the commented line above it
floorName.x = bigMapX0 + m*cellWidth;
floorName.y = bigMapY0 + n*cellHeight;
}
}
this.stop();
- 格雷格
解决方案
因为这个
"floorRC"+String(n)+String(m);
在某些情况下,对于不同的n和m对会产生相同的结果,例如
- (n = 1, m = 12)
- (n = 11, m = 2)
另一个
"floorR"+String(n)+"C"+String(m);
将始终产生一个唯一的String。
推荐阅读
- ruby-on-rails - 使用设计的电子邮件确认
- java - 如何创建字符串或字符类型的二维列表?
- python - AttributeError: 'str' 对象在运行 Tkinter 时没有属性 'tk'
- laravel - 我应该在哪里定义将在刀片模板中使用的逻辑?
- laravel - 如何解决图像干预渲染速度问题?
- react-native - 未捕获的 ReferenceError:使用 React-Native web 时未定义导出
- postgresql - 模式匹配 Postgres 以替换列的拼写错误的单词
- linux-kernel - v4l2 在使用 async kapi 时控制子设备上的继承
- r - 函数返回错误:矩阵错误(NA_character_,nrow = nrow(indt),ncol = Ncol):无效的“ncol”值(太大或 NA)
- node.js - PM2 Process Manager 没有显示每个项目 package.json 版本的实际版本,而是 NVM 版本号