好的,我有一个页面,上面有 5 个影片剪辑/按钮。当您将鼠标悬停在每一个上时,它们会亮起(OVER 状态),当您单击它们时,它们会展开(DOWN 状态)。问题是,如果您展开了多个影片剪辑(处于“向下”状态),它们会重叠并且看起来很糟糕。我想对它们进行编码,以便一次只能扩展 1 个。我怎样才能做到这一点?我想我需要在每个按钮上有一个 IF 语句,例如“如果任何其他影片剪辑处于 DOWN 状态,则禁用此影片剪辑的 DOWN 状态,如果没有其他按钮处于 DOWN 状态,则启用此影片剪辑的 DOWN 状态”或类似的内容但我不知道怎么写。请帮忙。以下是其中一个影片剪辑的代码:
Step0btn.stop();
Step0btn.addEventListener(MouseEvent.MOUSE_DOWN, onStep0Press);
Step0btn.addEventListener(MouseEvent.MOUSE_OVER, onStep0Over);
Step0btn.addEventListener(MouseEvent.MOUSE_OUT, onStep0Out);
function onStep0Press(event:MouseEvent):void
{
// toggle between frame 1 and 3 on button press
Step0btn.gotoAndStop(Step0btn.currentFrame == 3 ? 1 : 3);
}
function onStep0Over(event:MouseEvent):void
{
if (Step0btn.currentFrame != 3)
{
Step0btn.gotoAndStop(2);
}
}
function onStep0Out(event:MouseEvent):void
{
// only switch back to UP state if the button is "pressed"
if (Step0btn.currentFrame != 3)
{
Step0btn.gotoAndStop(1);
}
}
好的,我们已经解决了重叠影片剪辑的问题,但是在影片剪辑的“向下”状态下,另一个影片剪辑具有以下代码:
Step0img.stop();
Step0img.addEventListener(MouseEvent.MOUSE_DOWN, onStep0imgPress, false, 999);
function onStep0imgPress(event:MouseEvent):void
{
Step0img.gotoAndStop(2);
event.stopImmediatePropagation();
}
这使我可以单击嵌套的影片剪辑,甚至无需触发鼠标按下并关闭展开的影片剪辑。我认为禁用 MOUSECHILDREN 可能也会禁用此功能。
这是可以完成的一种方法:将上面的代码替换为按钮时间线上的此代码(或者更好的是创建一个类文件,并让每个按钮都将其作为基类,就像我的回答一样)这个问题 https://stackoverflow.com/questions/23351096/as3-multiple-rollover-objects/23355106#23355106- 那么您只需要拥有所有按钮共享的一个代码文件)
stage.addEventListener(MouseEvent.MOUSE_DOWN,globalMouseDown,false,0,true); //add a global mouse listener
function globalMouseDown(e:Event):void {
//find out if the target is a descendant of this, if not, then something else was clicked.
var tmpParent:DisplayObject = e.target as DisplayObject;
while(tmpParent && tmpParent != stage){
if(tmpParent == this) return;
tmpParent = tmpParent.parent;
}
//something else was clicked that wasn't this, so go to the up state
gotoAndStop(1);
}
stop();
addEventListener(MouseEvent.MOUSE_DOWN, onPress);
addEventListener(MouseEvent.MOUSE_OVER, onOver);
addEventListener(MouseEvent.MOUSE_OUT, onOut);
function onPress(event:MouseEvent):void
{
// toggle between frame 1 and 3 on button press
gotoAndStop(Step0btn.currentFrame == 3 ? 1 : 3);
}
function onOver(event:MouseEvent):void
{
if (currentFrame != 3)
{
gotoAndStop(2);
}
}
function onOut(event:MouseEvent):void
{
// only switch back to UP state if the button is "pressed"
if (currentFrame != 3)
{
gotoAndStop(1);
}
}
本文内容由网友自发贡献,版权归原作者所有,本站不承担相应法律责任。如您发现有涉嫌抄袭侵权的内容,请联系:hwhale#tublm.com(使用前将#替换为@)