2015-11-16 76 views
1

我搜索了这一点,但我认为答案是如此基本的我无法找到它(我已经做了闪光灯5天)我应该使用什么事件(显然不是的MouseEvent)[我超级新AS3]

我有一堆的对象,当一个被点击我的项目上去了,任何时候的物品> = 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; 
    } 
} 
+0

IT不清楚问题是什么?点击某件商品时没有任何反应?你的代码在哪里?那是什么'merch.b1'?似乎所有你需要做的就是在你的'grabB1'函数中调用'payUp()',因为你不想让用户点击三叶草? – BadFeelingAboutThis

+0

是的,我想点击'merch.b1'并有三叶草发光。现在,当我点击merch.b1时,只要点击它,三叶草就会发光。如果我在点击merch.b1之前点击三叶草,它不会发光(这是正确的)(我也有'merch.b2','merch.b3'等,但我没有将这些代码排除在外) –

回答

0

如果我理解正确的话,你有一堆物品(只1显示在你的代码中以保持简单?merch.b1?)。当任何这些项目被点击,你想使clover光芒,如果你的items var为大于或等于1

如果我有这个权利,那么这应该回答你的问题(有一些提示抛出,以减少冗余代码)。

//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 
} 
+0

感谢这有助于很多!还要感谢其他代码的建议! –

相关问题