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 5942941
In Process

The Archive Base Latest Questions

Editorial Team
  • 0
Editorial Team
Asked: May 22, 20262026-05-22T16:19:26+00:00 2026-05-22T16:19:26+00:00

The problem I am having is basically, I am instantiating the ‘Target’ object five

  • 0

The problem I am having is basically, I am instantiating the ‘Target’ object five times on the stage. This is happening, but only one object is able to have hitTestPoint performed on it. Can anyone help as to why this is happening?

Here is the code:

UPDATED

package {

import flash.display.Sprite;
import flash.events.MouseEvent;
import flash.ui.Mouse;
import flash.text.*;

public class TheGameItself extends Sprite {

    public var main_class:TheGame;
    private var crosshair:Crosshair = new Crosshair;
    private var targets:Array = new Array();

    public function TheGameItself(passed_class:TheGame) {

        main_class = passed_class;

        addTargets(4);

        Mouse.hide();
        addChild(crosshair);
        crosshair.x = mouseX;
        crosshair.y = mouseY;
        addEventListener(MouseEvent.MOUSE_MOVE, moveCrosshair);
    }

    private function addTargets(numOfTargets:int):void {
        for (var i:int = 0; i < numOfTargets; ++i) {
            targets[i] = new Target;
            targets[i].x = 100 * i + 70;
            targets[i].y = 100;
            targets[i].scaleX = targets[i].scaleY = .7;
            addChild(targets[i]);
            addEventListener(MouseEvent.CLICK, collisionDetection);
        }
    }

    private function collisionDetection(e:MouseEvent):void {
        targets.forEach(detectCollision);
    }

    private function detectCollision(element:*, index:int, targets:Array):void {
        if (element.hitTestPoint(mouseX, mouseY, true) && targets.length > 0) {
            trace("["+index+"]"+" "+element);
            collisionNotification.text = "Yes";
        } else {
            collisionNotification.text = "No";
        }
    }

    public function moveCrosshair(e:MouseEvent):void {
        crosshair.x = mouseX;
        crosshair.y = mouseY;
    }

}

}
  • 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-05-22T16:19:27+00:00Added an answer on May 22, 2026 at 4:19 pm

    Add your targets to an array to keep track of then:

    private function target:Array = new Array();
    
    private function newTarget(numOfTargets:uint):void {
            for (var i:int = 0; i < numOfTargets; i++) {
                target[i] = new Target;
                target[i].x = 100 * i + 70;
                target[i].y = 100;
                target[i].scaleX = target[i].scaleY = .7;
                addChild(target[i]);
                trace(target[i]); // Adds 5 objects to stage
    
                //**updated**
                target[i].addEventListener(MouseEvent.CLICK, collisionDetection); 
            }
    }
    

    now you can refer to each individual target:

    private function collisionDetection(e:MouseEvent):void {
    
    var target:MovieClip = MovieClip(e.target); //**updated**
    
            if (target.hitTestPoint(mouseX, mouseY, true)) {
                collisionNotification.text = "Collision";
                removeTarget();
                currentScore.text = String(int(score));
            } else {
                collisionNotification.text = "No collision";
                decreaseScore();
                currentScore.text = String(int(score));
                // Check if score is equal to -200 and if it is, show game over screen
                if (score == -500) {
                    Mouse.show();
                    main_class.showGameOver();
                }
            }
        }
    
    • 0
    • Reply
    • Share
      Share
      • Share on Facebook
      • Share on Twitter
      • Share on LinkedIn
      • Share on WhatsApp
      • Report

Sidebar

Related Questions

I'm having a problem using UpdateModel(theModelToUpdate) causing concurrency issues. Basically whats happening is, there
This is an annoying problem I am having with Twisted.web. Basically, I have a
I'm having a problem sorting this out, basically it will be a list with
I am having problem with serializing object before send to the wire. Basically I
I'm having this problem, where basically, I have a big array, that I break
I am completely stuck with this problem I'm having with excel. Basically I am
So I am having this problem wit my download link. Basically my previous way
Having a problem deploying an MVC application. Basically the site loads correctly, the home
I am having a problem with binding values in my ActionScript components. I basically
I'm having some problem with MKMapView / annotations / UINavigationController. Basically, i manage my

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.