Copy link to clipboard
Copied
Im a highschool student making a game for my CPT using flash CS6 (Coding with action script 3). I was wondering what the code would be for something hitting a target, and from there going to a random frame. Each frame has a question on it. So I want it to be a different question everytime they hit the target. So the Projectile hits the target, and a random question pops up.
Thanks for the help
Aaron
Copy link to clipboard
Copied
Put the frame numbers in an array and then shuffle the array so it is in random order. Then you can just go thru the array one item at a time. For the hitting a target aspect, look into using the hitTestObject() method. What you would do is continuously check if there is a hit until whatever passes that would signify the end of a need to check (like the end of the journey for the missile or the missile hitting the target)
Copy link to clipboard
Copied
Don't forget to remove the frame number from the array after it has been visited if you don't want to be repeatedly going to the same questions.
Copy link to clipboard
Copied
Thanks for the help! I will try this
Copy link to clipboard
Copied
You're welcome. You do not need to remove anything from the array if you go thru it from start to finish one item at a time. You won't repeat any frames until you finish going thru it and start at the beginning again. When you complete the array you could shuffle it again if you like or just leave it alone and repeat.
Here is a function you can use for shuffing the array into a random order...
function shuffle(a:Array) {
var p:int;
var t:*;
var ivar:int;
for (ivar = a.length-1; ivar>=0; ivar--) {
p=Math.floor((ivar+1)*Math.random());
t = a[ivar];
a[ivar] = a
;
a
= t;
}
}
// Usage:
shuffle(anArray);
Find more inspiration, events, and resources on the new Adobe Community
Explore Now