|
|
按钮一般会有三种状态。。。
但选择按钮被点击后,如果想区别于没有被点击的按钮的时候。在FLASH中,是比较难实现的。
以下是效果跟代码:
//AS3培训官方网站 http://www.flashdown.net
var myarray:Array=new Array();
for (var i:uint=1; i<4; i++) {
this["btn" + i].addEventListener(MouseEvent.CLICK,_CLICK);
this["btn" + i].addEventListener(MouseEvent.MOUSE_OVER,_OVER);
this["btn" + i].addEventListener(MouseEvent.MOUSE_OUT,_OUT);
myarray.push(this["btn" + i]);
}
function _CLICK(e:MouseEvent):void {
e.currentTarget.gotoAndStop(3);
e.target.removeEventListener(MouseEvent.MOUSE_OVER,_OVER);
e.target.removeEventListener(MouseEvent.MOUSE_OUT,_OUT);
for (var i:uint=1; i<4; i++) {
if (e.target!=myarray[i-1]) {
myarray[i - 1].gotoAndStop(1);
myarray[i - 1].addEventListener(MouseEvent.MOUSE_OVER,_OVER);
myarray[i - 1].addEventListener(MouseEvent.MOUSE_OUT,_OUT);
}
}
}
function _OVER(e:MouseEvent):void {
e.currentTarget.gotoAndStop(2);
}
function _OUT(e:MouseEvent):void {
e.currentTarget.gotoAndStop(1);
}
或者这种方法也可以:
for (var i:uint=1; i<4; i++) {
this["btn" + i].addEventListener(MouseEvent.CLICK,_CLICK);
this["btn" + i].addEventListener(MouseEvent.MOUSE_OVER,_OVER);
this["btn" + i].addEventListener(MouseEvent.MOUSE_OUT,_OUT);
this["btn" + i].I=i;
}
function _CLICK(e:MouseEvent):void {
for (var j:uint=1; j<4; j++) {
this["btn" + j].gotoAndStop(1);
this["btn" + j].addEventListener(MouseEvent.MOUSE_OVER,_OVER);
this["btn" + j].addEventListener(MouseEvent.MOUSE_OUT,_OUT);
if (e.currentTarget.I==j) {
e.currentTarget.removeEventListener(MouseEvent.MOUSE_OVER,_OVER);
e.currentTarget.removeEventListener(MouseEvent.MOUSE_OUT,_OUT);
e.currentTarget.gotoAndStop(3);
}
}
}
function _OVER(e:MouseEvent):void {
e.currentTarget.gotoAndStop(2);
}
function _OUT(e:MouseEvent):void {
e.currentTarget.gotoAndStop(1);
}
|
|
|