我应该使用什么事件(显然不是 MouseEvent)[我是 as3 的超级新手]

What Event should I use (clearly not MouseEvent) [I'm super new to as3]

我搜索过这个,但我认为答案太基础了,我找不到(我已经做了 5 天的 Flash)

我有一堆物体,当点击其中一个时,我的物品会上升,只要物品 >= 1,我想要一个不同的物体(三叶草)发光。

我正在使用 MouseEvent 执行此操作,但我无法让三叶草发光,除非我单击该对象...所以显然 MouseEvent.CLICK 不是我想要的。我只希望对象在我的项目 >=1 时发光。下面的代码(为了简洁起见,我已经对其进行了编辑,所以我可能遗漏了一些东西,但是当我 运行 它时我没有得到任何错误)

//import greensock
import com.greensock.*;
import flash.events.MouseEvent;

//make a variable to count items
var items = 0;

//add a click event to the clover
clover.addEventListener(MouseEvent.CLICK, payUp); //this is where i think it's wrong...

//click on b1 merch item
merch.b1.addEventListener(MouseEvent.CLICK, grabB1)

function grabB1(e: MouseEvent): void {
 //make the item disappear and add 1 to items
merch.b1.visible = false;
items++
merch.b1.removeEventListener(MouseEvent.CLICK, grabB1)
}

//explain the payUp function
function payUp(m:MouseEvent){
if (items >= 1) {
    //make the clover glow green
    TweenMax.to(clover, 0.5, {glowFilter:{color:0x66CC00, alpha:1, blurX:40, blurY:40}});
    clover.buttonMode = true;
    clover.useHandCursor = true;
    }
}

如果我没理解错的话,你有一堆物品(为了简单起见,你的代码中只显示了一件?merch.b1?)。单击这些项目中的任何一项时,如果 items var 大于或等于 1.

,您希望使 clover 发光

如果我说得对,那么这应该可以回答您的问题(并提供了一些减少冗余代码的技巧)。

//add a click event to the clover
clover.addEventListener(MouseEvent.CLICK, cloverClick);
//disable the ability to click the clover at first
clover.mouseEnalbled = false;
clover.mouseChildren = false;

//click listeners for your items
merch.b1.addEventListener(MouseEvent.CLICK, itemClick);

function itemClick(e:MouseEvent):void {
    //make the item disappear

    var itemClicked:DisplayObject = e.currentTarget as DisplayObject;
    //e.currentTarget is a reference to the item clicked
    //so you can have just this one handler for all the items mouse clicks

    itemClicked.visible = false;

    //if you want the item to be garbage collect (totally gone), you also need to remove it from the display (instead of just making it invisible)
    itemClicked.parent.removeChild(itemClicked);

    items++
    itemClicked.removeEventListener(MouseEvent.CLICK, itemClick);

    //now see if the clover needs to grow
    playUp();
}

//explain the payUp function
function payUp(){
    if (items >= 1) {
        //make the clover glow green
        TweenMax.to(clover, 0.5, {glowFilter:{color:0x66CC00, alpha:1, blurX:40, blurY:40}});

        //make the clover clickable
        clover.buttonMode = true;
        clover.useHandCursor = true;
        clover.mouseEnalbled = true;
        clover.mouseChildren = true;
    }
}

function cloverClick(e:Event):void {
    //do whatever you need to do when the clover is clicked
}