'Flash Hit Test Object as3

Ok I need help to figure out how to make it when the stuntman collides with the hoop it adds one point but instead it detects the collision multiple times and adds 5 points.Thanks for the help. This is my code:

stop();

// Variables to increase money

var totalmoney = 0;

var moneygain:int = 1;

var moneylimit:int = 100000;


//on collision with hoop add 1 point to money

addEventListener(Event.ENTER_FRAME, HoopCollision);

function HoopCollision(event:Event):void
{
  if(startstuntman.hitTestObject(starthoop))
  {
    totalmoney += moneygain;
  }
  Total.text = totalmoney;
  trace("HIT");
}


Solution 1:[1]

Best thing to do is to dynamically add attribute by adding:

stop();
    
var totalmoney = 0;

var moneygain:int = 1;

var moneylimit:int = 100000;

starthoop["hit"] = new Boolean(false); // *** initial is not hit by startstuntman ***


addEventListener(Event.ENTER_FRAME, HoopCollision);

function HoopCollision(event:Event):void
{
  if(startstuntman.hitTestObject(starthoop) && starthoop.hit == false) // *** checking additional expression ***
  {
    totalmoney += moneygain;
    starthoop.hit = true; // *** starthoop is now hit, so next time it checks, it wont increase totalmoney because of additional expression***
  }
  Total.text = totalmoney;
  trace("HIT");
}

Sources

This article follows the attribution requirements of Stack Overflow and is licensed under CC BY-SA 3.0.

Source: Stack Overflow

Solution Source
Solution 1 Dharman