Skip to main content
chienbleu
Known Participant
February 12, 2023
Question

as3 collision with multiple movieclips with same instance name

  • February 12, 2023
  • 1 reply
  • 274 views

I have to instances of the same movieclip with the same instance name but it only works for one. I don't want that. I've looked up many ways to do this but I'm a sort of begginer coder so I don't really get what it means or how to implement it into my code. I don't get how "for loops" and stuff work but I know it involves looping through all the instances but I just don't get it. Please explain a simple way to do this and why. Here's the code:

 

"

star.gotoAndStop("off")
stage.addEventListener(Event.ENTER_FRAME,loop)
function loop(event:Event)
{
star.x = mouseX
star.y = mouseY
if (rectangle.hitTestObject(star))
{
star.gotoAndStop("on")
}
else
{
star.gotoAndStop("off")
}
}

"

This topic has been closed for replies.

1 reply

kglad
Community Expert
Community Expert
February 12, 2023

don't use the same instance name, ever.

chienbleu
chienbleuAuthor
Known Participant
February 13, 2023

but what if i want to have a hundred of the same movieclip. i don't wanna have to name all of them individually

kglad
Community Expert
Community Expert
February 13, 2023

then name them using as3 or use parent.getChildAt()