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

Collision Detection hitTestObject not working.. ish

Participant ,
Aug 27, 2015 Aug 27, 2015

Copy link to clipboard

Copied

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

Views

893

Translate

Translate

Report

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?

Votes

Translate

Translate
Community Expert ,
Aug 27, 2015 Aug 27, 2015

Copy link to clipboard

Copied

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.

Votes

Translate

Translate

Report

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

Copy link to clipboard

Copied

can you put it in the code for me please?

Votes

Translate

Translate

Report

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

Copy link to clipboard

Copied

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?

Votes

Translate

Translate

Report

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

Copy link to clipboard

Copied

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

Thanks for your help.

Votes

Translate

Translate

Report

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

Copy link to clipboard

Copied

LATEST

you're welcome.

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

Votes

Translate

Translate

Report

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