OMFG AS: MAINZ0R!!1
This is the ultimate how to make random things code. I see random movement was done, so I won't cover that. Lets start with random x and random y positions!
Random x and y positions
Start out by making a movieclip *draw something and hit F8* and give it the instance name of "Reed" without quotes. Now make a button *draw something, hit F8 and select button* and put this code in it *to open the AS window, hit F9*
CODE
on(release) {
_root.Reed._x = Math.random()*400;
_root.Reed._y = Math.random()*400;
}
Let me explain this, this is a simple cood meaning, when you release the button, the movie clip "Reed" moves to a random location between 1 and 400. It's a simple code that can be edited to make VERY cool things, like powerups. EXAMPLE
Random Numbers
This is a simple one too, in fact they're all pretty simple. Make a dynamic textbox *make a textbox, hit ctrl + F3 and switch to dynamic* and give it the instance and variable name "bb" without quotes. Now make a button under it and put this code in it:
CODE
on(release) {
_root.bb = (Math.round(Math.random()*10));
}
this means when you release the button, the textbox "bb" will generate a random number between 1 and 10. You can make it generate a random number with higher digits by raising the "*10" part of the code. Math.round makes it so it wont have a decimal.
NOTE: you can change "round" to "ceil" and "floor", round means round to the nearest, ceil means round up, and floor means round down.
EXAMPLE
GotoAndPlay RANDOM!
This will be the last part of the tutorial. What you need to do is make a movieclip, and put stop() in the first frame inside of it. After that, make10 frames, it doesn't matter what they are, I used differen't colors, and make a button (outside the mc) and put this code in it.
CODE
on(release) {
_root.gf.gotoAndStop(Math.round(Math.rando
m()*10));
}
This will make it go to a random frame between 1 and 10, again, you can change that by changing the number at the end, and you can change the way it rounds by switching round to ceil or floor. Thanks for reading my tutorial on random codes, I hope you learned something! Remember, you don't have to just stick with what I gave you, you can do all sorts of things, by editing the code! Good luck!
-Reedo11-