我正在尝试按下每个按钮更新我的程序登录*请参见下面的图片,但是它只会在第一次按下时显示数据。我不确定那是不是因为它处于for循环中。
停止(); import flash.events.MouseEvent;
var MAX_ORGANISMS: int = 12;
var MAX_GENES: int = 2;
var genotype: Array = new Array();
var MAX_PARENTS: int = 2; // number of parents organisms to select
var MAX_CHILDREN: int = 2; // number offspring per selected parent
var generation: int = 0; // to count the generation being shown
var list_selected: Array = new Array(); // list of selected org.
var number_selected: int;
var geno_text: String = "";
function random_genotype_initialisation(): void {
generation = 0;
number_selected = 0;
var org: int;
for (org = 0; org < MAX_ORGANISMS; org++) {
list_selected[org] = 0;
var genotype_1organism: Array = new Array();
genotype_1organism[0] = randomRangeInteger(1, 4);
// gene1 = head colour (4 types)
genotype_1organism[1] = randomRangeInteger(46, 49);
// gene2 = head width (44 - 48)
genotype_1organism[2] = randomRangeInteger(50, 55);
// gene3 = head legnth
genotype_1organism[3] = randomRangeInteger(1, 4);
// gene4 = eye type (4 types)
genotype_1organism[4] = randomRangeInteger(30, 35);
// gene5 = eye width (30 - 35)
genotype_1organism[5] = randomRangeInteger(1, 4);
// gene6 = nose type (4 types)
genotype_1organism[6] = randomRangeInteger(10, 18);
// gene7 = nose height (10 - 18)
genotype[org] = genotype_1organism.slice();
}
}
function randomRangeInteger(min: int, max: int): int {
var randomNum: int = Math.floor(Math.random() * (max - min + 1)) + min;
return randomNum;
}
function show_phenotype(): void {
var org: int;
var org_property: String;
for (org = 0; org < MAX_ORGANISMS; org++) {
org_property = "o" + org + "_head";
this[org_property].gotoAndStop(genotype[org][0]);
this[org_property].width = genotype[org][1];
this[org_property].height = genotype[org][2];
org_property = "o" + org + "_eyes";
this[org_property].gotoAndStop(genotype[org][3]);
this[org_property].width = genotype[org][4];
org_property = "o" + org + "_nose";
this[org_property].gotoAndStop(genotype[org][5]);
this[org_property].height = genotype[org][6];
geno_text += "Geno" + org + " has initialised." + "This Geno has a " + genotype[org][1] + " by " + genotype[org][2] + " face" + "\n" ;
geno_log.text = geno_text;
}
}
function initialise(event: MouseEvent) {
random_genotype_initialisation();
show_phenotype();
}
initialise_btn.addEventListener(MouseEvent.MOUSE_UP, initialise);
程序有一些面孔,每次用户按下初始化按钮时会随机改变功能。据我所知,按钮处理程序工作正常,程序运行正常,但是文本不适用,只更改一次。