Motimot
Motimot

Reputation: 59

Detect which movieclip you hit (AS3)

Im developing a game in AS3, And I ran into problem. I have the movieclip: ExitPoints. And inside this movieclip, there some other movieclips like: e_1, e_2, e_3 and e_4. When the player hit the ExitPoints movieclip, I want the game to trace which movieclip the player is standing on (e_1 or e_2 or e_3 or e_4).

I know I can make a code like:

if(player.hitTestObject(ExitPoint.e_1){
}

but I want to do it automaticlly with creating a lot of if statements. Any help?

Upvotes: 1

Views: 74

Answers (1)

Velocirooster
Velocirooster

Reputation: 646

This can be accomplished using a loop that loops through all the exits contained in an array.

var exits:Array = [ExitPoint.e_1, ExitPoint.e_2, ExitPoint.e_3, ExitPoint.e_4];

for(var i:int = 0; i < exits.length; i++) {
    if(player.hitTestObject(exits[i])) {
        //do something
    }
}

Upvotes: 3

Related Questions