Solved

Test collision in ActionScript of multiple objects

Posted on 2009-05-02
3
316 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
[X]
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
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

What does it mean to be "Always On"?

Is your cloud always on? With an Always On cloud you won't have to worry about downtime for maintenance or software application code updates, ensuring that your bottom line isn't affected.

Question has a verified solution.

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

Recently, I was asked to recommend a tracking system to be implemented on a clients website. As the entire site was built on flash, my first thought was to suggest custom built tracking system. However, our company at that point of time didn't h…
I have been doing hardcore actionscripting for some time; and needless to say I have faced a lot of problems in just understanding others' code rather than understanding what the code executes. A programmer's life can become hell when there are a lo…
In this tutorial viewers will learn how to create a basic shape tween animation in Flash including shape hints for smooth animation Open a new document in Flash: Draw a shape: Select another frame (how long you want the tween to be): Right click and…
The goal of the tutorial is to teach the user how to how to load their YouTube profile onto Flash Media Live Encoder.

624 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