Tek-Tips is the largest IT community on the Internet today!

Members share and learn making Tek-Tips Forums the best source of peer-reviewed technical information on the Internet!

  • Congratulations Mike Lewis on being selected by the Tek-Tips community for having the most helpful posts in the forums last week. Way to Go!

HELP-MovieClips, array, instance, for loop, dont know

Status
Not open for further replies.

PmtAce

Technical User
Apr 6, 2006
17
US
I am developing things for others as a template. However, because they dont know actionscript, my code has to be able to mend to what they have. One of the things I am doing is making a maze game. However, I am not specifying how many wall they must have. So therefore, if I use a hitTest, I wouldnt know how many to use. So I want to use an array and for loop. The idea is that they will enter the number of walls, and the for loop will go through all the walls and detect if they hit it.
For example, I thought it would go like:

// walls are named wall1, wall2, wall3, etc.
for (i=1;i<numberOfWallsVariable;i++){
if (this.hitTest(_root.wall)){
//what I want to happen
exit for;
}
}

This way if they had 4 walls, it would check to see if it hit any of the 4 walls and if it did, it would carry out the code. However, for some reason it doesnt work. I believe it is because instance arrays are different in actionscript than in other languages. Could someone tell me what I am doing wrong. Thanks in advance.
 
Never mind. I did a little trial and error and found away to get it to work. For those who are looking at this for an answer, I did:

onClipEvent(enterFrame){
for (i = 2;i<5;i++){
if (this.hitTest(_root.menu1["menu" + i])){
_root.score = _root.score + 1;
// or whatever
}
}
}
 
Status
Not open for further replies.

Part and Inventory Search

Sponsor

Back
Top