var clips:Array = [tu1, tu2, tu3, tu4, tu5, tu6, tu7, tu8, tu9]; // 存储所有影视剪辑的数组 var STATE_NORMAL:Number = 1; var STATE_OVER:Number = 2; var STATE_SELECTED:Number = 3; for (var i:Number = 0; i < clips.length; i++) { var clip:MovieClip = clips[i]; clip.gotoAndStop(STATE_NORMAL); clip.selected = false; // 添加一个selected属性并初始化为false clip.useHandCursor = true; clip.addEventListener(MouseEvent.ROLL_OVER, onRollOver); clip.addEventListener(MouseEvent.ROLL_OUT, onRollOut); clip.addEventListener(MouseEvent.CLICK, onClick); } function onRollOver(event:MouseEvent):void { trace("onRollOver called"); updateState(event.currentTarget as MovieClip, STATE_OVER); } function onRollOut(event:MouseEvent):void { trace("onRollOut called"); var clip:MovieClip = event.currentTarget as MovieClip; if (!clip.selected) { updateState(clip, STATE_NORMAL); } } function onClick(event:MouseEvent):void { trace("onClick called"); var clip:MovieClip = event.currentTarget as MovieClip; if (clip.selected) { return; } for (var j:Number = 0; j < clips.length; j++) { var c:MovieClip = clips[j]; c.selected = false; updateState(c, STATE_NORMAL); } clip.selected = true; updateState(clip, STATE_SELECTED); } function updateState(clip:MovieClip, state:Number):void { clip.gotoAndStop(state); if (state == STATE_SELECTED) { clip.mc_normal.visible = false; clip.mc_over.visible = false; clip.mc_selected.visible = true; } else if (state == STATE_OVER) { clip.mc_normal.visible = false; clip.mc_over.visible = true; clip.mc_selected.visible = false; } else { // STATE_NORMAL clip.mc_normal.visible = true; clip.mc_over.visible = false; clip.mc_selected.visible = false; } }改为as2语言
时间: 2023-06-27 16:02:07 浏览: 112
var clips:Array = [tu1, tu2, tu3, tu4, tu5, tu6, tu7, tu8, tu9]; // 存储所有影视剪辑的数组
var STATE_NORMAL:Number = 1;
var STATE_OVER:Number = 2;
var STATE_SELECTED:Number = 3;
for (var i:Number = 0; i < clips.length; i++) {
var clip:MovieClip = clips[i];
clip.gotoAndStop(STATE_NORMAL);
clip.selected = false; // 添加一个selected属性并初始化为false
clip.useHandCursor = true;
clip.onRollOver = function() {
trace("onRollOver called");
updateState(this, STATE_OVER);
};
clip.onRollOut = function() {
trace("onRollOut called");
var clip:MovieClip = this;
if (!clip.selected) {
updateState(clip, STATE_NORMAL);
}
};
clip.onClick = function() {
trace("onClick called");
var clip:MovieClip = this;
if (clip.selected) {
return;
}
for (var j:Number = 0; j < clips.length; j++) {
var c:MovieClip = clips[j];
c.selected = false;
updateState(c, STATE_NORMAL);
}
clip.selected = true;
updateState(clip, STATE_SELECTED);
};
}
function updateState(clip:MovieClip, state:Number):void {
clip.gotoAndStop(state);
if (state == STATE_SELECTED) {
clip.mc_normal._visible = false;
clip.mc_over._visible = false;
clip.mc_selected._visible = true;
} else if (state == STATE_OVER) {
clip.mc_normal._visible = false;
clip.mc_over._visible = true;
clip.mc_selected._visible = false;
} else {
// STATE_NORMAL
clip.mc_normal._visible = true;
clip.mc_over._visible = false;
clip.mc_selected._visible = false;
}
}
阅读全文