2015-11-16 54 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

感謝這有助於很多!還要感謝其他代碼的建議! –

相關問題