根据测验的得分,任务是产生几根浅色和深色羽毛。浅色羽毛代表正确的点(light_feather
),黑色羽毛是不正确的点(dark_feather
)(每个都被跟踪)。所有的羽毛都应该在一条线上排成一行,这意味着第一根羽毛,然后是黑色的羽毛。我得到了测验动力学,我在这里发布的功能仅适用于他们按下结束测验的时候。
var light_feather:LightFeather = new LightFeather();
var dark_feather:DarkFeather = new DarkFeather();
var good_answers:uint = 0;
var bad_answers:uint = 0;
function avsluttFunc (evt:MouseEvent)
{
var sum_LightFeatherX:Number = 0;
for (var i = 0; i < good_answers; i++) {
addChild(light_feather);
light_feather.x += 12 + (i*16);
light_feather.y = 0;
trace("Lys X-verdi: " + light_feather.x);
sum_LightFeatherX += Number(light_feather.x);
return sum_LightFeatherX;
}
trace(sum_LightFeatherX);
dark_feather.x += sum_LightFeatherX;
for (var j = 1; j <= bad_answers; j++) {
addChild(dark_feather);
dark_feather.x += 12 + (j*16);
dark_feather.y = 0;
trace("Mørk X-verdi: " + dark_feather.x);
}
/*
//Resetter poengsummen
good_answers = 0;
bad_answers = 0;
*/
}
答案 0 :(得分:0)
你可以只用一个for循环来做你想要的东西,看看:
ei32cu.write_database()
此代码示例将在2个var good_answers:uint = 2;
var bad_answers:uint = 4;
function avsluttFunc(evt:MouseEvent)
{
for (var i:int = 0; i < good_answers + bad_answers; i++) {
var feather:DisplayObject = i < good_answers ? new LightFeather() : new DarkFeather();
feather.x += 12 + i * (feather.width + 1);
feather.y = 0;
addChild(feather);
}
}
个实例旁边创建4个DarkFeather
个实例。
修改:
如何将对象添加到数组中?
LightFeather
然后将它们从舞台上移除,你可以做到例如:
// feathers array should be accessible for both codes (adding and removing objects)
var feathers:Array = [];
for (var i:int = 0; i < good_answers + bad_answers; i++) {
var feather:DisplayObject = i < good_answers ? new LightFeather() : new DarkFeather();
addChild(feather);
feathers.push(feather);
}
希望可以提供帮助。