AS3如何使只有1影片剪辑可点击的时候有多个影片剪辑影片剪辑、多个、时候

由网友(起航)分享简介:好了,我有上5影片剪辑/按钮的页面。当你的鼠标移到每一个,他们点亮(悬停状态),当你点击他们,他们扩大(向下状态)。现在的问题是,如果你有扩大(在DOWN状态)它们重叠多个影片剪辑,它看起来可怕。我想code所以他们只有1个可以同时展开。我怎样才能做到这一点?我想我需要在每个按钮的IF语句,如如果任何其他影片剪辑处于停...

好了,我有上5影片剪辑/按钮的页面。当你的鼠标移到每一个,他们点亮(悬停状态),当你点击他们,他们扩大(向下状态)。现在的问题是,如果你有扩大(在DOWN状态)它们重叠多个影片剪辑,它看起来可怕。我想code所以他们只有1个可以同时展开。我怎样才能做到这一点?我想我需要在每个按钮的IF语句,如如果任何其他影片剪辑处于停机状态,然后禁用下来这个影片剪辑,如果没有其他按钮处于向下状态,则启用向下状态,这个影片剪辑或类似的东西但我不知道怎么写。请帮忙。这里是code为影片剪辑中的一个:

Ok, so I have a page with 5 movieclips/buttons on it. When you mouse over each one they light up (OVER state) and when you click on them they expand (DOWN state). The problem is if you have multiple movieclips expanded (in the DOWN state) they overlap and it looks awful. I want to code them so only 1 can be expanded at a time. How can I do this? I imagine I need an IF statement on each button like "If any other movieclips are in the DOWN state, then disable DOWN for this movieclip, if no other buttons are in DOWN state then enable the DOWN state for this movieclip" or something like that but I don't know how to write it. Please help. Here is the code for one of the movieclips:

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);
    }
} 

好了,我们已经解决了这个问题,重叠影片剪辑,但是在影片剪辑的向下状态还有另外一个影片剪辑具有这种code:

Ok we have solved the issue with the overlapping movieclips, however on the movieclip's DOWN state there is another movie clip that has this code:

Step0img.stop();

Step0img.addEventListener(MouseEvent.MOUSE_DOWN, onStep0imgPress, false, 999);

function onStep0imgPress(event:MouseEvent):void
{
    Step0img.gotoAndStop(2);
    event.stopImmediatePropagation();
}

这让我点击嵌套的影片剪辑,而不会触发鼠标按下甚至闭展开影片剪辑。我认为禁止将mouseChildren可能也禁用此功能。

This allowed me to click on the nested movieclip without triggering the MOUSE DOWN even and closing the expanded movieclip. I think disabling the MOUSECHILDREN may have also disabled this functionality.

推荐答案

这里有一种方法可以做到这一点:更换code以上这个code对您的按钮时间表(或更好,但使一个类每个文件和你的按钮有它像我的回答this问题 - 那么你只需要拥有一个code文件,所有的按钮股)

Here is one way this can be done: Replace the code above with this code on your button timelines (or better yet make a class file and have your buttons each have it as their base class like my answer to this question - then you only need to have the one code file that all your buttons share)

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);
    }
} 
阅读全文

相关推荐

最新文章