如何使鼠标悬停在下面的剪辑事件仍然有效?

时间:2011-08-19 01:36:52

标签: actionscript-3 flash-cs5

您好希望有人可以帮我解决此MOUSE_OVER事件问题

我通过按钮上的MOUSE_OVER触发工具提示的外观,我发现如果我将鼠标指针放在工具提示上,它会一直触发。工具提示和按钮都是MovieClips

我该如何防止这种情况?

以下是我的代码片段:

for(var i:Number=0; i < MapContainer.numChildren; i++) {
    var Country:MovieClip = MapContainer.getChildAt(i) as MovieClip;
    if(Country){ // make sure its a movieclip
        trace('Found movieclip');
        addInfoBubble(Country);
        Country.addEventListener(MouseEvent.MOUSE_OVER, countryMouseOver);
        Country.addEventListener(MouseEvent.MOUSE_OUT, countryMouseOut);
    } 

}

function showInfoBubble(Country:MovieClip){

    var bubble = getChildByName(Country.name+"Info");
    trace("bubble name " + bubble);
    bubble.visible = true;
    TweenLite.to(bubble, .5, {alpha:1});

}

function hideInfoBubble(Country:MovieClip){
    var bubble = getChildByName(Country.name+"Info");
    bubble.alpha = 0;
    bubble.visible = false;
    //removeChild(CountryInfo);
    //CountryInfo = null;
}

function countryMouseOver(e:Event):void{
    trace('countryMouseOver '+e.target);
    var countryMc = e.target;
    var localPos:Point = new Point(countryMc.x,countryMc.y);
    var globalPos:Point = countryMc.localToGlobal(localPos);
    trace('local pos: '+localPos+ ' global pos:'+globalPos);

    TweenLite.to(countryMc, 1, {tint:mouseOverColor});

    showInfoBubble(countryMc);
}

function countryMouseOut(e:Event):void{
    trace('countryMouseOut '+e.target);
    var countryMc = e.target;
    var localPos:Point = new Point(countryMc.x,countryMc.y);
    var globalPos:Point = countryMc.localToGlobal(localPos);
    trace('local pos: '+localPos+ ' global pos:'+globalPos);

    TweenLite.to(countryMc, 1, {tint:mouseOutColor});
    hideInfoBubble(countryMc);
}

由于

1 个答案:

答案 0 :(得分:1)

无论您在何处创建bubble MovieClip(看起来像是在addInfoBubble中),请设置bubble.mouseEnabled = false;

另外,正如您从StackOverflow语法高亮显示中看到的那样,通过约定变量通常以小写名称开头,具有大写名称的类(国家/地区参数应为国家/地区)。