tellTarget("/wino/wo"+win0)用ActionScript 3.0 优化
时间: 2024-03-16 08:42:23 浏览: 13
在 ActionScript 3.0 中,可以使用点操作符和字符串拼接符号进行优化,例如:
```
wino["wo" + win0];
```
这将访问 `wino` 对象下以字符串 "wo" 和变量 `win0` 拼接而成的属性。如果需要对该属性进行赋值,可以这样写:
```
wino["wo" + win0] = value;
```
需要注意的是,在 ActionScript 3.0 中,不建议使用字符串拼接符号来构建对象路径,因为这样容易导致代码混乱和错误。建议在代码中尽可能使用点操作符来访问对象的属性和方法。
相关问题
tellTarget("/winx/wx"+winx)用ActionScript 3.0 优化
在 ActionScript 3.0 中,可以使用点操作符和字符串拼接符号进行优化,例如:
```
winxContainer["wx" + winx];
```
这将访问 `winxContainer` 对象下以字符串 "wx" 和变量 `winx` 拼接而成的属性。如果需要对该属性进行赋值,可以这样写:
```
winxContainer["wx" + winx] = value;
```
需要注意的是,在 ActionScript 3.0 中,不建议使用字符串拼接符号来构建对象路径,因为这样容易导致代码混乱和错误。建议在代码中尽可能使用点操作符来访问对象的属性和方法。
if (win == 1) { endwx = 0; penok = 0; tellTarget("/winx/wx" add winx) { gotoAndPlay(2); } } if (win == 0) { endwx = 0; penok0 = 0; tellTarget("/wino/wo" add win0) { gotoAndPlay(2); } } if (win == 2) { endwx = 1; }使用 ActionScript 3.0优化
使用 ActionScript 3.0 优化上述代码可以改写为:
```actionscript
switch (win) {
case 1:
endwx = 0;
penok = 0;
winx.gotoAndPlay(2);
break;
case 0:
endwx = 0;
penok0 = 0;
wino.gotoAndPlay(2);
break;
case 2:
endwx = 1;
break;
}
```
这样可以使用 switch 语句代替多个 if 语句,使代码更加简洁和易读。同时,直接访问对象属性 winx 和 wino 并调用它们的 gotoAndPlay() 方法可以取代 tellTarget() 方法。