actionstript random frame question
- Started
- Last post
- 8 Responses
- nebrow
question:
I have a header/flash navigation of a webpage and i need it to load one of 5 images when the movie loads. Ive tried googling it but i cant find anythign for going to a random frame label instead of random frame. this link was sort of helpful http://www.flashmove.com/board/s… but not exactly what i was looking for.
Any help for a flash newbie?
- acescence0
you only have 5 possible results, so just map those five digits to frame labels. if number == 1 goto frame label 1, etc..
- kinetic0
or forget the labels and just do the frame numbers
just dont let your random pick 0 or flash might go ballistic since the frame numbers start at 1
if you have 10 frames for example:
number = Math.round(Math.random() * (9)) + 1;
gotoAndStop(number);
- nebrow0
i have been trying this from something that i have googled:
_root.onLoad = function() {
// define a array with all your previously defined labels
labelarray=["a","b","c","d"];// calculate a random index for this array
randomidx = random(labelarray.length);// jump to the label at the random index
gotoAndStop(labelarray[randomIdx...
}this seems beyond my simple actionscripting skills...or im just an idiot but i cant figure this out at all!
- rson0
You need stop(); on yer frames:)
- rson0
haha im wrong ;(
- rson0
but what kintec wrote works
number = Math.round(Math.random() * (9)) + 1;gotoAndStop(number);
stop();just replace all the scipt on frame 1
- nebrow0
even simpler:
i put this in my first frame
gotoAndStop (int(Random(4)+1));
that works...i dunno wtf that code i first posted was doing...
thanks for the help though!
- joyride0
va r myArray : Array = new Arra y("label1 ","label2","label3","label4","la... );
someVariable = Math . floor (M ath . r andom( ) * 5);
Should work fine for you