Solved

Test collision in ActionScript of multiple objects

Posted on 2009-05-02
3
303 Views
Last Modified: 2013-11-11
If I have the movie clips: ball0_mc, ball1_mc, ball2_mc &&.. ball50_mc    and I will like to test if any ball hits a movie clip named target_mc then do I have to type:?

if (ball0_mc.hitTestObject(target_mc) || ball1_mc.hitTestObject(target_mc) || ball2_mc.hitTestObject(target_mc) .......  ball50_mc.hitTestObject(target_mc)  ) {
trace("hit");
}

Is there a way of testing a collision if the movie clip contains the word ball for example? In other words to test the collision of all the movie clips that contains the word ball with the movie clip target_mc?
0
Comment
Question by:TonoNam
3 Comments
 
ID: 24288948
Use hitTest method...


0
 

Author Comment

by:TonoNam
ID: 24290244
I am not familiar with that method. should I write something like hitTest(target_mc)? Moreover I am new to ActionScript 3.0
0
 
LVL 1

Accepted Solution

by:
davidwestfall earned 125 total points
ID: 24291002
You need to setup an array to hold all of the balls.  Once you have the array setup, you can check for the collision like this.
for(var i:int = 0; i < balls.length; i ++) {

     var ball = balls[i];

     trace(ball.hitTestObject(target_mc));

}

Open in new window

0

Featured Post

Better Security Awareness With Threat Intelligence

See how one of the leading financial services organizations uses Recorded Future as part of a holistic threat intelligence program to promote security awareness and proactively and efficiently identify threats.

Join & Write a Comment

This is a very simple example to help those of you who are still migrating from AS2 to AS3 understand the redesigned event model in AS3. In AS2.0, event functions (that is, the function to be performed when an event is fired) were stored as a pro…
This article describes a solution to a problem of subloading one movie into another when they have different SWF versions. Sometime back, I was working on an ActionScript project while I came across an interesting fact which I would like to share…
The goal of the tutorial is to teach the user how to how to record live broadcast.
The goal of the tutorial is to teach the user how to use the auto adjust feature and what the different options do. When your video is not working right you can choose the auto adjust feature to help choose your settings.

759 members asked questions and received personalized solutions in the past 7 days.

Join the community of 500,000 technology professionals and ask your questions.

Join & Ask a Question

Need Help in Real-Time?

Connect with top rated Experts

25 Experts available now in Live!

Get 1:1 Help Now