我制作了 2 个阵列,一个用于命名昆虫部位,另一个用于显示昆虫的部位。滚动由数组和 for 循环创建的按钮,部件和按钮会亮起。但我也希望部件和按钮在翻过昆虫部件时亮起。我的问题是我不知道在翻过昆虫部位时如何从循环中调用按钮。请参阅函数 rollHandler2 和 outHandler2。
//the arrays look like this...
var parts:Array= [ "Cervical sclerites", "Protonotopleural lobe", "Proepisternum",...]
var shapes:Array = [pt0, pt1, pt2, ...]
for (var i:int = 0; i < parts.length; i++){
var b:MovieClip = new Btn();
but.x = 15;
but.y = ((i)*(b.height+1))+10;
but.name = "b"+i;
but.info.text = parts[i];
but.buttonMode = true;
but.info.mouseEnabled=false;
addChild(b);
but.addEventListener(MouseEvent.ROLL_OVER, rollHandler);
but.addEventListener(MouseEvent.ROLL_OUT, outHandler);
//b.addEventListener(MouseEvent.CLICK, outHandler);
}
for (var j:int = 0; j < shapes.length; j++){
shapes[j].buttonMode = true;
shapes[j].addEventListener(MouseEvent.ROLL_OVER, rollHandler2);
shapes[j].addEventListener(MouseEvent.ROLL_OUT, outHandler2);
}
function rollHandler(event:MouseEvent):void {
for (var i:int = 0; i < parts.length; i++) {
if (event.currentTarget.name == "b"+i) {
this.shapes[i].gotoAndStop("over");
event.currentTarget.gotoAndStop("over");
}
}
}
function outHandler(event:MouseEvent):void {
for (var i:int = 0; i < parts.length; i++) {
if (event.currentTarget.name == "b"+i) {
this.but[i].gotoAndStop("start");
event.currentTarget.gotoAndStop("start");
}
}
}
function rollHandler2(event:MouseEvent):void {
for (var i:int = 0; i < shapes.length; i++) {
if (event.currentTarget == shapes[i]) {
this.parts[i].gotoAndStop("over");
//How should i call the button b created from the parts loop?
event.currentTarget.gotoAndStop("over");
}
}
}
function outHandler2(event:MouseEvent):void {
for (var i:int = 0; i < shapes.length; i++) {
if (event.currentTarget == shapes[i]) {
this.b[i].gotoAndStop("start");
//same problem here.. Not sure how to call it.
event.currentTarget.gotoAndStop("start");
}
}
}