Exit
  • Global community
    • Language:
      • Deutsch
      • English
      • Español
      • Français
      • Português
  • 日本語コミュニティ
  • 한국 커뮤니티
0

Collision Detection hitTestObject not working.. ish

Participant ,
Aug 27, 2015 Aug 27, 2015

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"

  }

}

TOPICS
ActionScript
1.1K
Translate
Report
Community guidelines
Be kind and respectful, give credit to the original source of content, and search for duplicates before posting. Learn more
community guidelines

correct answers 1 Correct answer

Community Expert , Aug 27, 2015 Aug 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?

Translate
Community Expert ,
Aug 27, 2015 Aug 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.

Translate
Report
Community guidelines
Be kind and respectful, give credit to the original source of content, and search for duplicates before posting. Learn more
community guidelines
Participant ,
Aug 27, 2015 Aug 27, 2015

can you put it in the code for me please?

Translate
Report
Community guidelines
Be kind and respectful, give credit to the original source of content, and search for duplicates before posting. Learn more
community guidelines
Community Expert ,
Aug 27, 2015 Aug 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?

Translate
Report
Community guidelines
Be kind and respectful, give credit to the original source of content, and search for duplicates before posting. Learn more
community guidelines
Participant ,
Aug 27, 2015 Aug 27, 2015

OK got it. I had to addChild it instead of pre position them on stage.

Thanks for your help.

Translate
Report
Community guidelines
Be kind and respectful, give credit to the original source of content, and search for duplicates before posting. Learn more
community guidelines
Community Expert ,
Aug 27, 2015 Aug 27, 2015
LATEST

you're welcome.

p.s when using the adobe forums, please mark helpful/correct responses, if there are any.

Translate
Report
Community guidelines
Be kind and respectful, give credit to the original source of content, and search for duplicates before posting. Learn more
community guidelines