Sign Up

Sign Up to our social questions and Answers Engine to ask questions, answer people’s questions, and connect with other people.

Have an account? Sign In

Have an account? Sign In Now

Sign In

Login to our social questions & Answers Engine to ask questions answer people’s questions & connect with other people.

Sign Up Here

Forgot Password?

Don't have account, Sign Up Here

Forgot Password

Lost your password? Please enter your email address. You will receive a link and will create a new password via email.

Have an account? Sign In Now

You must login to ask a question.

Forgot Password?

Need An Account, Sign Up Here

Please briefly explain why you feel this question should be reported.

Please briefly explain why you feel this answer should be reported.

Please briefly explain why you feel this user should be reported.

Sign InSign Up

The Archive Base

The Archive Base Logo The Archive Base Logo

The Archive Base Navigation

  • SEARCH
  • Home
  • About Us
  • Blog
  • Contact Us
Search
Ask A Question

Mobile menu

Close
Ask a Question
  • Home
  • Add group
  • Groups page
  • Feed
  • User Profile
  • Communities
  • Questions
    • New Questions
    • Trending Questions
    • Must read Questions
    • Hot Questions
  • Polls
  • Tags
  • Badges
  • Buy Points
  • Users
  • Help
  • Buy Theme
  • SEARCH
Home/ Questions/Q 8332503
In Process

The Archive Base Latest Questions

Editorial Team
  • 0
Editorial Team
Asked: June 9, 20262026-06-09T02:44:35+00:00 2026-06-09T02:44:35+00:00

Okay, I have an array in my Main Class that looks like this: objectArray:Array

  • 0

Okay, I have an array in my Main Class that looks like this:

objectArray:Array = [ ];

I have three functions that create different items such as coins, enemies, hearts etc. Each of these added items are pushed into the objectArray. I am trying to write this function that hittests my bullets against any of these objects:

private function checkCollisions() :void{
    var bullet:MovieClip;
    for (var j:int = 0; j < objectArray.length; j++){
        object = objectArray[j];
        for(var i:int = 0; i < bulletArray.length; i++){
            bullet = bulletArray[i];
            if (objectArray[j].hitTestPoint(bullet.x, bullet.y, true)) {
                container.removeChild(bullet);
                bulletArray.splice(i,1);

                if (objectArray[j] == Enemy[j]){
                    container.removeChild(objectArray[j]);
                    objectArray.splice(j,1);
                    trace("enemy hit");
                }
            }
        }
    }
}

The problem is coming from this part:

if (objectArray[j] == Enemy[j]){  \\problem
    container.removeChild(objectArray[j]);
    objectArray.splice(j,1);
    trace("enemy hit");
}

I keep trying to figure a way to test the object that is being Hittested against a certain value such as “Enemy” so that I can produce different results based on what kind of object is being hit. No matter what combination of tests I try, I can’t seem to get it to respond. When I trace objectArray[j], it produces [object Enemy] as a result. Is there a different way of testing Array values?

  • 1 1 Answer
  • 0 Views
  • 0 Followers
  • 0
Share
  • Facebook
  • Report

Leave an answer
Cancel reply

You must login to add an answer.

Forgot Password?

Need An Account, Sign Up Here

1 Answer

  • Voted
  • Oldest
  • Recent
  • Random
  1. Editorial Team
    Editorial Team
    2026-06-09T02:44:36+00:00Added an answer on June 9, 2026 at 2:44 am

    It sounds like you want to test if the object in objectArray[j] is an Enemy object. You can do this with the is operator:

    if (objectArray[j] is Enemy)
    {
        container.removeChild(objectArray[j]);
        trace ("enemy hit");
    }
    

    Edit

    Also, you might want to iterate over the bullet/object array’s in reverse order, since you are potentially deleting entries from the array as you iterate over it.

    for (var j:int = objectArray.length -1; j >= 0; j--){
     // then do the same with the bullet array
    
    • 0
    • Reply
    • Share
      Share
      • Share on Facebook
      • Share on Twitter
      • Share on LinkedIn
      • Share on WhatsApp
      • Report

Sidebar

Related Questions

Okay, I have an array that is used to transport names, it looks like
Okay so you have and array A[]... that is passed to you in some
Okay, my dilemma is this. I have an admin page that I use to
Okay, so I have this array. Currently it pulls multiple payment amounts and dates
I have a array which contains values like this See below for script sample
Okay, I have a multi-dimensional array which is statically-allocated. I'd very much like to
Okay, this one is pretty complicated... lets say I have an array called $data
okay i have been trying to understand this for hours i am learning VB
Okay I have a large CRUD app that uses tabs with Forms embedded in
Okay I have a series of objects based on a base class which are

Explore

  • Home
  • Add group
  • Groups page
  • Communities
  • Questions
    • New Questions
    • Trending Questions
    • Must read Questions
    • Hot Questions
  • Polls
  • Tags
  • Badges
  • Users
  • Help
  • SEARCH

Footer

© 2021 The Archive Base. All Rights Reserved
With Love by The Archive Base

Insert/edit link

Enter the destination URL

Or link to existing content

    No search term specified. Showing recent items. Search or use up and down arrow keys to select an item.