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

How to find the objects names which hit on other object

New Here ,
Apr 13, 2015 Apr 13, 2015

Copy link to clipboard

Copied

Dear Friends,

I am moving a movieclip on the screen every where on the screen, during the movement I will hit or overlap other objects on the screen. I want to find the name of the objects which hit or overlap my movieclip.

for example I used trace(my_mc.hitTestObject(objnames). Here the objnames may be any object(movie clips) on the screen. I want to find which object hitted my movieclip..

please help me...its like a game project.

Thanks in Advance,

Syed Abdul Rahim

TOPICS
ActionScript

Views

1.1K

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

Guru , Apr 14, 2015 Apr 14, 2015

My fault, i had a typo in my loop:

var i:int = 0; 1<this.numChildren;i++


should be


var i:int = 0; i<this.numChildren;i++



Now it works as expected



Votes

Translate

Translate
New Here ,
Apr 13, 2015 Apr 13, 2015

Copy link to clipboard

Copied

trace(my_mc.hitTestObject(objnames).

I mean I want to find the objnames here..

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
New Here ,
Apr 14, 2015 Apr 14, 2015

Copy link to clipboard

Copied

Dear Friends,

Pls reply me.... How can I find the hitted object name, My object will move with my mouse and hit or overlap the objects in the screen.. I want to get those name (name of the objects)... pls help me to find...

Thanks in advance,

Syed Abdul Rahim

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
Guru ,
Apr 14, 2015 Apr 14, 2015

Copy link to clipboard

Copied

with an object named "myObject" on stage:

stage.addEventListener(MouseEvent.MOUSE_MOVE, detectCollision);

function detectCollision(e:MouseEvent):void{

for (var i:int = 0; 1<this.numChildren;i++){

//don`t test an objects collision with itself

   if (getChildAt(i).name != "myObject"){

  if(myObject.hitTestObject(getChildAt(i)){

   trace("my Object hit " +getChildAt(i).name;

     }

   }

}

CAVEAT: Flash native collision detection has low standards, it`s not designed to detect collisions of complex shapes.

For Pixel Perfect collision detection you will have to look further

Pixel Perfect Collision Detection | Free ActionScript

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
New Here ,
Apr 14, 2015 Apr 14, 2015

Copy link to clipboard

Copied

Dear Mr.Moccamaxium,

Thks for the reply.. iam getting the following error:

RangeError: Error #2006: The supplied index is out of bounds. at flash.display::DisplayObjectContainer/getChildAt() at Untitled_fla::MainTimeline/detectCollision()

in ur code I have adjusted the parenthesis...like below:

stage.addEventListener(MouseEvent.MOUSE_MOVE, detectCollision);

function detectCollision(e:MouseEvent):void
{
for (var i:int = 0; 1<this.numChildren-1; i++)
{
  trace("test "+this.numChildren);
  //don`t test an objects collision with itself
  if (getChildAt(i).name != "myObject")
  {
   trace(i);
   if (myObject.hitTestObject(getChildAt(i)))
   {

    trace("my Object hit " +getChildAt(i).name);
   }
  }
}
}

Thanks in Advance,

Syed Abdul Rahim

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
Guru ,
Apr 14, 2015 Apr 14, 2015

Copy link to clipboard

Copied

My fault, i had a typo in my loop:

var i:int = 0; 1<this.numChildren;i++


should be


var i:int = 0; i<this.numChildren;i++



Now it works as expected



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
New Here ,
Apr 15, 2015 Apr 15, 2015

Copy link to clipboard

Copied

Thanks a lot Mr.Moccamximum...Thank u so much...

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
Guru ,
Apr 15, 2015 Apr 15, 2015

Copy link to clipboard

Copied

LATEST

You`re welcome 😉

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
New Here ,
Apr 14, 2015 Apr 14, 2015

Copy link to clipboard

Copied

Dear Mr.Moccamaxium,

Thks for the reply.. iam getting the following error:

RangeError: Error #2006: The supplied index is out of bounds. at flash.display::DisplayObjectContainer/getChildAt() at Untitled_fla::MainTimeline/detectCollision()

in ur code I have adjusted the parenthesis...like below:

stage.addEventListener(MouseEvent.MOUSE_MOVE, detectCollision);

function detectCollision(e:MouseEvent):void
{
for (var i:int = 0; 1<this.numChildren-1; i++)
{
  trace("test "+this.numChildren);
  //don`t test an objects collision with itself
  if (getChildAt(i).name != "myObject")
  {
   trace(i);
   if (myObject.hitTestObject(getChildAt(i)))
   {

    trace("my Object hit " +getChildAt(i).name);
   }
  }
}
}

Thanks in Advance,

Syed Abdul Rahim

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