为什么 object.name 中的这些更改会导致不同的显示?
Why do these changes in object.name result in different displays?
我正在做一些简单的事情 - 绘制一系列图块,将它们放置在库中并在属性中进行链接,然后创建一个由随机选择的图块组成的大矩形。我还希望能够独立访问每个图块,因此我为每个图块使用了数组类型的命名系统。然后我遇到了这种情况,如果我使用变量彼此相邻的命名方案(而不是拆分他们用字符串文字)。
谁能解释一下原因:
floor.name = "floorR"+字符串(n)+"C"+字符串(m); //表现正常,如预期
给出不同的显示结果:
floor.name = "floorRC"+字符串(n)+字符串(m); //转换为下面代码中的注释,往往会放错tile
在以下最少的、可重现的提取物中:
//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。
我正在做一些简单的事情 - 绘制一系列图块,将它们放置在库中并在属性中进行链接,然后创建一个由随机选择的图块组成的大矩形。我还希望能够独立访问每个图块,因此我为每个图块使用了数组类型的命名系统。然后我遇到了这种情况,如果我使用变量彼此相邻的命名方案(而不是拆分他们用字符串文字)。
谁能解释一下原因: floor.name = "floorR"+字符串(n)+"C"+字符串(m); //表现正常,如预期
给出不同的显示结果: floor.name = "floorRC"+字符串(n)+字符串(m); //转换为下面代码中的注释,往往会放错tile
在以下最少的、可重现的提取物中:
//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。