2013-03-08 72 views
0

如果我創建了一個if語句,並且我希望它在目標點擊另一個影片剪輯時執行某些操作(但我已經知道該如何操作),但只有當它正確的目標,我該怎麼做?動作腳本3如何使if語句與數組激活

function stopdrag(e:MouseEvent):void{ 
    e.currentTarget.stopDrag(); 
    if(e.currentTarget.hitTestObject(destination) || //right here is where the script would `check the name of the target//){` 
     scaryface.visible=true; 
    } 
} 

我該如何確保它只在目標是數組中的特定值時才起作用?

回答

0

您可以創建該目標的自定義屬性,如ID(arr [0] .ID =「abc」)或創建該數組時的類似內容,然後您可以檢查該ID。

如果條件是你試圖匹配數組中的任何值,那麼你可以檢查for循環中的索引。

0

我無法確切地告訴你在問什麼。如果你想檢查目標是否包含一個數組裏面,你可以使用類似下面的代碼:

function stopdrag(e:MouseEvent):void{ 
    e.currentTarget.stopDrag(); 
    if(e.currentTarget.hitTestObject(destination) && yourArray.indexOf(e.currentTarget) > 0){ 
     scaryface.visible=true; 
    } 
} 

這將檢查目標是否與目標,如果是碰撞會檢查是否達到了目標包含在yourArray中。

0

你可以設置一個開關/箱或嵌套if語句...如果你沒有目標了難以置信的大量...例如:

if (e.currentTarget.hitTestObject(destination1){ 
doSomething(); 
}else if{ 
(e.currentTarget.hitTestObject(destination2){ 
doSomethingElse(); 
} 

Elsewise,像VIPUL的解決方案上面是相當明智

0

我想做到這一點不用考慮性能的最簡單,最懶的方法是

if(array.indexOf(e.currentTarget) >= 0){ 
    //do something 
}