代码很好地说明了这个问题,我已经把所有不相关的东西都删掉了。
游戏开始时创建2-4个亲属
function createInitialKinsmen()
{
for (var k:int = 1; k < 3 + Math.round(Math.random() * 2; k++)
{
if (k == 1)
{
createKinsmen(0);
trace ("player");
}
else
{
createKinsmen(1);
trace ("starting kinsmen");
}
}
}
亲属创造功能
function createKinsmen(arrivalTypeVar:int)
{
var newKinsmen = new kinsmen;
listPanel.kinsmenDivider.addChild(newKinsmen);
totalKinsmen++;
totalKinsmenAlive++;
newKinsmen.name = "kinsmen" + totalKinsmen;
newKinsmen.arrivalType = arrivalTypeVar;
}
亲属班
public class kinsmen extends MovieClip
{
var arrivalType:int;
function kinsmen()
{
trace(this.name);
if (this.arrivalType = 0)
{
trace("player");
}
if (this.arrivalType = 1)
{
trace("starting kinsmen");
}
}
}
输出应该说:
kinsmen1
player
player
kinsmen2
starting kinsmen
starting kinsmen
kinsmen3
starting kinsmen
starting kinsmen
kinsmen4
starting kinsmen
starting kinsmen
而是说:
kinsmen1
player
player
kinsmen2
player
starting kinsmen
kinsmen3
player
starting kinsmen
kinsmen4
player
starting kinsmen
这意味着没有传递arrivalType变量。似乎可以传递硬编码的变量,因此目前我在 kinsmen 电影剪辑中有一个带有 alpha 0 的正方形,它的 x 位置决定了构造函数中到达类型的值,但这肯定不是一个好习惯,是有更好的方法吗?