Monster Racer Rush
Select between 5 monster racers, upgrade your monster skill and win the competition!
4.18 / 5.00 3,534 ViewsBuild and Base
Build most powerful forces, unleash hordes of monster and control your soldiers!
3.80 / 5.00 4,200 ViewsHi. Ive been working at this for a while, but still cant get it. I need to attach (using attachMovie) a random movieclip every x amount of milliseconds (ill probably be using random intervals). I know how to use attachMovie, I don't know how to attach random movieclips. I'll explain. Say I have 5 Mcs. Lets call them sword, gun, knife, dagger, and missile. I want one of those 5 to appear every x amount of seconds, and have it completely random. How should I go about doing this?
Example codes would really help, and a little explanation. Thanks a lot for any help.
Using an array would probably be the best way to do it. If you don't know how they work, go and read about them in AS:Main, if you do:
-Make an array containing the 'linkage-names' of the mc's that you want to attach
-Then do something like this when attaching:
attachMovie(yourArrayName[random(yourArrayName.length-1)], etc.., etc...) At 10/10/07 07:17 PM, Legzl wrote: Hi. Ive been working at this for a while, but still cant get it. I need to attach (using attachMovie) a random movieclip every x amount of milliseconds (ill probably be using random intervals). I know how to use attachMovie, I don't know how to attach random movieclips. I'll explain. Say I have 5 Mcs. Lets call them sword, gun, knife, dagger, and missile. I want one of those 5 to appear every x amount of seconds, and have it completely random. How should I go about doing this?
Example codes would really help, and a little explanation. Thanks a lot for any help.
Well it would involve intervals.
This is how I make random countdowns
var timer:Number = 0;
var randomCounter:Number= Math.ceil(Math.random()*5); //will create a number from 1 to 5
function fPlus(){
timer +=0.1;
}
setInterval(fPlus, 1000);
onClipEvent(enterFrame){
if (randomCounter>=timer){
timer=0;
randomCounter=Math.ceil(Math.random()*5)
; //randomized countdown
//attach your movie clip here
}}
to randomly select a MC generate a random number like this
Math.ceil(Math.random()*number of MCs);
then attach an MC depending on what value you get from the randomizer.
Flash is happy and it knows it.
Thanks guys. I'm gonna go with Dreamworx way and see how it works, as it was the way I originally tried. I was on the right track, just forgot to use the length method. I'll tell you if it works.
var myInterval:Number;
spawnWeapon = function(){
var rndNum:Number = Math.round(Math.random() * 4);
switch(rndNum){
case 0: var weapon = "dagger";
case 1: var weapon = "sword";
//And so on
default: "var weapon = "default"; //eg. none
}
attachMovie(weapon, "newWeapon", getNextHighestDepth();
}
myInterval = setInterval(this. spawnWeapon, 1000);
Just adapt this code to fit your cause.
Worst case scenario: Paste it into flash, click on the words you dont understand (switch, case, setInterval, etc.) and press F1.