AS: Main
---------------
First off, you will need to learn about arrays and the random code.
---------------
What you will learn
In this tutorial, you will learn 2 things to do with the random code. The first thing you will learn is how to make a button play frames at random. IE- A button will randomly choose between frame numbers 2, 5, and 6. It will then play that frame. The second thing you will learn is how to make random words appear in text boxes.
---------------
Random Frame Thing
First off, make a button. You do this by drawing it, right clicking, selecting "Convert To Symbol" and then selecting button. After, that, give your button this code:
on(press){
framenum=new Array(frame1,frame2,frame3);
gotoAndPlay(framenum[random(3)]);
}
Important!!
Make sure you replace frame1, frame2, and frame 3 with 3 different frames of your choice. Also, make sure you have that many frames on your timeline. :-P
---------------
What It Does
First, when you press your button, it will create a new array named framenum. You can change framenum to whatever you want but make sure you change all traces of it in the code to the new value. Second, the button will play the specified numbers within the array at random. If you wanna add more values, just add some more numbers into the array and than change random(3) to the amount of values in the array.
---------------
Making Random Words Appear
I assume you know how to give textboxes random number values, but now you will learn how to give them random word values. First, make a dynamic text box with the var name of "wordz" without the quotes. Then, give the frame this code:
words=new Array("Bob","Joe","Daniel","SpamBurger");
_root.wordz=words[random(4)];
---------------
What It Does
First, flash will create a new array called words. Then, flash will give the dynamic text box, wordz, the value of words. It will choose randomly between one of the values within the array. As you can see, instead of giving the array number values, we give it word values, or as we flash junkies would call it, strings. Whenever using a string, you must give it quotes.
---------------
Button that changes it's value
Now, I will teach you how to make a button that will change its value. Like the first button code, it looks like this:
on(press){
_root.wordz=_root.words[random(4)];
}
Im assuming that would work but I created it right here on the BBS so I dont know.
---------------
How It Works
First, flash will perform the action when you press the button. Then, it will give the dynamic text box "wordz" a new value from the array of "words".
---------------
~Please post here any comments or suggestions.