Welcome to Experts Exchange

Add your voice to the tech community where 5M+ people, just like you, are talking about what matters.

  • Help others & share knowledge
  • Earn cash & points
  • Learn & ask questions
Solved

Test collision in ActionScript of multiple objects

Posted on 2009-05-02
3
310 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

Free Tool: Port Scanner

Check which ports are open to the outside world. Helps make sure that your firewall rules are working as intended.

One of a set of tools we are providing to everyone as a way of saying thank you for being a part of the community.

Question has a verified solution.

If you are experiencing a similar issue, please ask a related question

Suggested Solutions

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…
I have found that much of my time doing support ends up being a constant repetition of the same steps to different people.  Early on I stated using web pages with Frequently Asked Questions (FAQs) to alleviate most of the burden.  Sometimes this jus…
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.
This Micro Tutorial will teach to how to utilize bit rate in Adobe Flash Media Live Encoder.

809 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