如果它们被调用,我如何让一个动作覆盖多个其他动作?

How do I make a action over ride multiple other actions if they are being called?

我正在制作交互式地图。

当点击每个国家/地区时,一个信息框会出现在视图中,然后在延迟 5 秒后再次出现。这一切都很好。

//Algeria

    algeria_mc.addEventListener (MouseEvent.CLICK, showAlgeria)
    function showAlgeria (e:MouseEvent)
    {

            TweenLite.to(algeria_txt, 1, {autoAlpha:1});
            OverwriteManager.init(2);
            TweenLite.to(algeria_txt, 1, {autoAlpha:0, delay:5});   

    }




//Bahrain
    bahrain_mc.addEventListener (MouseEvent.CLICK, showBahrain)
    function showBahrain (e:MouseEvent)
    {

        TweenLite.to(bahrain_txt, 1, {autoAlpha:1});
        OverwriteManager.init(2);
        TweenLite.to(bahrain_txt, 1, {autoAlpha:0, delay:5});

    }

但是如果有人在延迟结束前 select 另一个国家,我会得到一个重叠的文本框。

我想用一种简短的方式来说明,如果任何其他国家/地区的文本框可见,请先将其设为不可见,然后再将 selected 设为可见。我不想一一列举每个国家/地区,因为它们有 20 多个。

有没有捷径可以做到这一点?我已将所有国家/地区放在一个数组中

var countrys_txt:Array =[algeria_txt, bahrain_txt, cote_txt, dubai_txt, dubai_txt, ghana_txt, iran_txt, jordan_txt, kenya_txt, kuwait_txt, libya_txt, oman_txt, safrica_txt, palestine_txt, mauritius_txt, qatar_txt, saudi_txt, sudan_txt, syria_txt, tunisia_txt, turkey_txt, yemen_txt, nigeria_txt];

我想也许我可以拜访这个?

请问最好的快速解决方案是什么?

这是您可以执行此操作的一种方法。

您创建一个 var 来存储当前信息框,每当显示一个新信息框时,您就隐藏当前信息框。

    import flash.display.MovieClip;
    import flash.events.TimerEvent;
    import flash.utils.Timer;

    //create a global var to hold a reference to the current info box
    var curInfoBox:MovieClip;

    //create a timer to make the current info box go away after 5 seconds (5000 milliseconds)
    var goawayTimer:Timer = new Timer(5000, 1);

    //run the goawayTimerTick function whenever the timer ticks
    goawayTimer.addEventListener(TimerEvent.TIMER, goawayTimerTick);

    function goawayTimerTick(e:TimerEvent) {
        if (curInfoBox) {
            hideInfoBox(curInfoBox);
        }
    }

    //create function to show an info box to reduce redundant code
    function showInfoBox(box:MovieClip) {
        TweenLite.to(box, 1, { autoAlpha:1 } );
        OverwriteManager.init(2);

        //if there's something in the curINfoBox var, hide it
        if (curInfoBox) {
            hideInfoBox(curInfoBox);
        }

        curInfoBox = box;

        //reset and start the timer to that makes it go away after 5 seconds
        goawayTimer.reset();
        goawayTimer.start();
    }

    function hideInfoBox(box:MovieClip) {
        TweenLite.to(box, 1, { autoAlpha: 0 } );
    }

    //now setup all your buttons
    algeria_mc.addEventListener (MouseEvent.CLICK, showAlgeria)
    function showAlgeria (e:MouseEvent)
    {
        showInfoBox(algeria_txt);
    }

您可以按照以下方式进一步减少冗余:

//create an array of all your country buttons
var mapButtons:Array = [algeria_mc, bahrain_mc, cote_mc, dubai_mc]; //etc with all of them

//iterate over that array and attach a click listener to each item
for(var i:int=0;i<mapButtons.legnth;i+){
    mapButtons[i].addEventListener(MouseEvent.CLICK, mapButtonClick);
}


function mapButtonClick(e:MouseEvent){
    //the passed event (e) has a property called currentTarget
    //that is a reference to object you attached the listener to, eg the item clicked

    //we take the instance name of the item clicked, and replace the _mc with _txt to get a reference to it's info box
    var infoBox:MovieClip = getChildByName(e.currentTarget.name.replace("_mc","_txt")) as MovieClip;

    //now show the box
    showInfoBox(infoBox);
}