Hit Tests + Arrayed objects [Flash AS2]

Started by: Steyene | Replies: 5 | Views: 578 | Closed

Steyene

Posts: 2,060
Joined: Apr 2006
Rep: 10

View Profile
Aug 24, 2008 6:38 AM #232277
I have an array with objects in it called square+square_num. There are 15 of them in total, and I am trying to get a hit test for them. But it isn't working.
onClipEvent(enterFrame){
for(i=1;i<=15;i++){
if(this.hitTest(_root["square"+i])){
_root.sqaure_base.speed = 0;
}
else{
_root.sqaure_base.speed = 5;
}
}
}

That could is from the object that is being run into. Please help if you can or if more code is needed just say so.
Scorpioxxx
2

Posts: 1,454
Joined: Apr 2006
Rep: 10

View Profile
Aug 24, 2008 1:27 PM #232440
onClipEvent(enterFrame){
for(i=1;i<=15;i++){
if(this.hitTest(_root.["square"+i])){
_root.square_base.speed = 0;
}
else{
_root.square_base.speed = 5;
}
}
}


Bolded the bits I changed. Just a '.' and spelling (I think)
Bonk
2

Posts: 2,778
Joined: Mar 2008
Rep: 10

View Profile
Aug 24, 2008 1:29 PM #232441
Where does the square_num come in?
Scorpioxxx
2

Posts: 1,454
Joined: Apr 2006
Rep: 10

View Profile
Aug 24, 2008 1:31 PM #232444
Quote from Bonk
Where does the square_num come in?


He's using variable 'i' to represent the number of squares I think.
Rather Cheesy
2

Posts: 2,137
Joined: Apr 2007
Rep: 10

View Profile
Aug 24, 2008 6:29 PM #232595
Yeah, Scorpio fixed the code as far as I can see. What you did was just typo's really, you missed a . on _root. and you miss-spelled square in the speed lines but the code I think you did correctly
Steyene

Posts: 2,060
Joined: Apr 2006
Rep: 10

View Profile
Aug 24, 2008 9:56 PM #232802
I fixed up the typos. But when I added the "." for the hit test part. It returned an error.

Edit:

Got it working, I needed to change the ["square"+i]'s speed not the base movie clips one >_>