Solved

Test collision in ActionScript of multiple objects

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

PeopleSoft Has Never Been Easier

PeopleSoft Adoption Made Smooth & Simple!

On-The-Job Training Is made Intuitive & Easy With WalkMe's On-Screen Guidance Tool.  Claim Your Free WalkMe Account Now

Question has a verified solution.

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

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 is intended to introduce all collision detection principles in flash, their strengths, weaknesses and workarounds. The main method for Collision Detection in flash is using hitTestObject. But unless you'll be pushing rectangular shapes without …
In this tutorial viewers will learn how to create a basic motion tween animation in Flash Open a new document in Flash: Draw/import an image: Press CTRL + F8 to convert it into a graphic symbol: Select a frame (how long you want the tween to last): …
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.
Suggested Courses

751 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