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
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
Copy link to clipboard
Copied
trace(my_mc.hitTestObject(objnames).
I mean I want to find the objnames here..
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
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
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
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
Copy link to clipboard
Copied
Thanks a lot Mr.Moccamximum...Thank u so much...
Copy link to clipboard
Copied
You`re welcome 😉
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