flash如何实现当前按钮按下,其他按钮弹起

2024-11-20 09:13:01
推荐回答(4个)
回答(1):

打散,换成你想要的按钮初始颜色,在第二帧上加关键帧,把文字换成鼠标点击后的颜色。(注意,要打散哦,不打散也行。我喜欢打散)在第一帧加上as命令stop();
同样方法制作一个按钮2.
回到舞台。把俩影片剪辑放到舞台上 然后命名按钮1为an1_mc按钮2为an2_mc
新建一图层,在第一帧上F9写上命令:
an1_mc.buttonMode=true;
an2_mc.buttonMode=true;
an1_mc.addEventListener(MouseEvent.MOUSE_OVER,an1mouseover);
function an1mouseover(e) {
an1_mc.gotoAndStop(2);

}

an2_mc.addEventListener(MouseEvent.MOUSE_OVER,an2mouseover);
function an2mouseover(e) {

an2_mc.gotoAndStop(2);
}
an1_mc.addEventListener(MouseEvent.MOUSE_OUT,an1mouseout);
function an1mouseout(e) {

an1_mc.gotoAndStop(1);
}
an2_mc.addEventListener(MouseEvent.MOUSE_OUT,an2mouseout);
function an2mouseout(e) {

an2_mc.gotoAndStop(1);
}
an1_mc.addEventListener(MouseEvent.MOUSE_DOWN,an1click);
function an1click(e) {
an1_mc.gotoAndStop(2);
an2_mc.gotoAndStop(1);
an1_mc.removeEventListener(MouseEvent.MOUSE_OUT,an1mouseout);
}
an2_mc.addEventListener(MouseEvent.MOUSE_DOWN,an2click);
function an2click(e) {
an1_mc.gotoAndStop(1);
an2_mc.gotoAndStop(2);
an2_mc.removeEventListener(MouseEvent.MOUSE_OUT,an2mouseout);
}
as的意思是昂。开始的时候把mc变成按钮模式。然后监听按钮的鼠标各类事件。具体很简单撒,我用的是很麻烦的方法,但好理解,有更简单的方法,楼主好好研究。ok,打完收工。

回答(2):

首先,这5个按钮都必须是影片剪辑,然后有两帧,第一帧上加stop();

然后,这5个按钮实例名分别为btn0,btn1,btn2,btn3,btn4

代码如下:

var btn_index:int=0;
for(var i:int=0;i<5;i++)
{
this["btn"+i].buttonMode=true;
this["btn"+i].addEventListener(MouseEvent.CLICK,MouseClickEvent);
}
btn0.gotoAndStop(2);
function MouseClickEvent(e:MouseEvent):void
{
var obj:Object=e.currentTarget;
var t:int=int(obj.name.slice(3));
if(t==btn_index)
{
return;
}
this["btn"+btn_index].gotoAndStop(1);
btn_index=t;
obj.gotoAndStop(2);
}

回答(3):

原理都是先将所有按钮gotoAndPlay(1),再单独设置按下的按钮gotoAndPlay(2)

AS2.0————————————————————————————————————
var btnArr:Array = [btn1, btn2, btn3, btn4, btn5];//舞台上五个按钮的名字放入数组
for(var i in btnArr){
btnArr[i].onPress = pressBtn;//每一个都添加点击事件
}

function pressBtn(){
for(var i in btnArr){
btnArr[i].gotoAndStop(1);//先把数组中所有按钮都退回第一帧
}
this.gotoAndStop(2);//把点击的按钮播放到第二针
}

AS3.0————————————————————————————————————
var btnArr:Array = [btn1, btn2, btn3, btn4, btn5];
for(var i in btnArr){
btnArr[i].buttonMode = true;//只是给按钮加个手型,此举不要也行
btnArr[i].addEventListener(MouseEvent.CLICK, clickBtn);
}

function clickBtn(e:MouseEvent){
var btn:MovieClip = e.currentTarget as MovieClip;
for(var i in btnArr){
btnArr[i].gotoAndStop(1);
}
btn.gotoAndStop(2);
}

回答(4):

btn1.addEventListener(MouseEvent.CLICK,clickHandler1);
btn2.addEventListener(MouseEvent.CLICK,clickHandler2);
btn3.addEventListener(MouseEvent.CLICK,clickHandler3);
btn4.addEventListener(MouseEvent.CLICK,clickHandler4);
btn5.addEventListener(MouseEvent.CLICK,clickHandler5);
function clickHander1(evt:MouseEvent):void{
gotoAndStop(2);
btn2.gotoAndStop(1);
btn3.gotoAndStop(1);
btn4.gotoAndStop(1);
btn5.gotoAndStop(1);
}
function clickHander2(evt:MouseEvent):void{
gotoAndStop(2);
btn1.gotoAndStop(1);
btn3.gotoAndStop(1);
btn4.gotoAndStop(1);
btn5.gotoAndStop(1);
}
function clickHander3(evt:MouseEvent):void{
gotoAndStop(2);
btn1.gotoAndStop(1);
btn2.gotoAndStop(1);
btn4.gotoAndStop(1);
btn5.gotoAndStop(1);
}
function clickHander4(evt:MouseEvent):void{
gotoAndStop(2);
btn1.gotoAndStop(1);
btn2.gotoAndStop(1);
btn3.gotoAndStop(1);
btn5.gotoAndStop(1);
}
function clickHander5(evt:MouseEvent):void{
gotoAndStop(2);
btn1.gotoAndStop(1);
btn2.gotoAndStop(1);
btn3.gotoAndStop(1);
btn4.gotoAndStop(1);
}