Skip to main content
deborahb44958436
Inspiring
August 27, 2015
Answered

Collision Detection hitTestObject not working.. ish

  • August 27, 2015
  • 1 reply
  • 1148 views

Obviously as you can see from this clip the Hit and Miss is not corresponding to the actual event on the stage. why? It works only if I give the objects instance name, but not working when using the var name. why?

here's the code:

import flash.events.Event;

var gball: SmallGreenBall1_T = new SmallGreenBall1_T();

var bucket: allBuckets = new allBuckets();

this.addEventListener(Event.ENTER_FRAME, handleCollision)

function handleCollision(evt: Event): void {

  if (gball.hitTestObject(bucket)) {

  output_txt.text = "HIT"

  } else {

  output_txt.text = "MISS"

  }

}

This topic has been closed for replies.
Correct answer kglad

maybe you just need to remove some code.  if you have a gball on-stage and a bucket on stage, use:

import flash.events.Event;

this.addEventListener(Event.ENTER_FRAME, handleCollision)

function handleCollision(evt: Event): void {

  if (gball.hitTestObject(bucket)) {

  output_txt.text = "HIT"

  } else {

  output_txt.text = "MISS"

  }

}

p.s. if that fails, is gball time-line tweened?

1 reply

kglad
Community Expert
Community Expert
August 27, 2015

bucket's at 0,0 though you can't see it because you failed to add it to the stage.

same with gball but you must be doing something with one or both of those two for the textfield text to change.

deborahb44958436
Inspiring
August 27, 2015

can you put it in the code for me please?

kglad
Community Expert
kgladCommunity ExpertCorrect answer
Community Expert
August 27, 2015

maybe you just need to remove some code.  if you have a gball on-stage and a bucket on stage, use:

import flash.events.Event;

this.addEventListener(Event.ENTER_FRAME, handleCollision)

function handleCollision(evt: Event): void {

  if (gball.hitTestObject(bucket)) {

  output_txt.text = "HIT"

  } else {

  output_txt.text = "MISS"

  }

}

p.s. if that fails, is gball time-line tweened?