Welcome Guest [Log In] [Register]
Welcome to Brackenwood. We hope you enjoy your visit.


You're currently viewing our forum as a guest. This means you are limited to certain areas of the board and there are some features you can't use. If you join our community, you'll be able to access member-only sections, and use many member-only features such as customizing your profile, sending personal messages, and voting in polls. Registration is simple, fast, and completely free.


Join our community!


If you're already a member please log in to your account to access all of our features:

Username:   Password:
Add Reply
Help with Random Function
Topic Started: Feb 11 2006, 12:07 PM (163 Views)
Andros
Member Avatar
Check my location.
Alright, I figured out that Math.random(); can make a random number between 0 and 1. How can I apply this to make something similar to chluaid's "random sarus word of the day?" In other words, how can I make a random phrase appear each time the thing is loaded?
Offline Profile Quote Post Goto Top
 
smoscar_01
Member Avatar
Mid-Level ActionScripter
The easiest way to do that is getting all your messages of the day at a frame of a movieclip named 'theword' and then at the first frame action youll need to add this

Code:
 
theword.gotoAndStop(random(theword._totalframes));
Offline Profile Quote Post Goto Top
 
Vector
Member Avatar
Resident Actionscript Guru ♂
Admin
don't forget the + 1, smoscar: The random function returns a value from 0 to the max number that you specified, - 1.

Code:
 
theword.gotoAndStop(random(theword._totalframes) + 1);


Should do the trick.

Math.random() was depreciated (is not supposed to be used) since MX I think.
Offline Profile Quote Post Goto Top
 
Mr. Jiggmin
Member Avatar
made of tulips
I think you've got your randoms confused, Vec.

Posted Image
Offline Profile Quote Post Goto Top
 
Andros
Member Avatar
Check my location.
I tried putting that code into the movieclip named "theword," but this pops up when I try it:

**Error** Scene=Scene 1, layer=Layer 1, frame=1:Line 1: Statement must appear within on/onClipEvent handler
theword.gotoAndStop(random(theword._totalframes) + 1);

Total ActionScript Errors: 1 Reported Errors: 1


With my limited knowledge, I tried "onClipEvent(enterFrame)." It got rid of the warning, but then it didn't work like it should have.
Offline Profile Quote Post Goto Top
 
Mr. Jiggmin
Member Avatar
made of tulips
That code needs to go on a keyframe, not a movie clip. Make a new layer, then make a blank keyframe where the movie clip is. With that frame selected, put that code in the code box thingy.

If you want to put the code on the movie clip then you'll want something more like this:
Quote:
 
onClipEvent (load) {
gotoAndStop(random(this._totalframes)+1);
}
Offline Profile Quote Post Goto Top
 
Andros
Member Avatar
Check my location.
Awesome. Thanks a million... well, maybe not. Can you break a twenty?
Offline Profile Quote Post Goto Top
 
smoscar_01
Member Avatar
Mid-Level ActionScripter
Quote:
 
don't forget the + 1, smoscar: The random function returns a value from 0 to the max number that you specified, - 1.


ooh yeah thanks vector hahaha :lol:

Quote:
 
Can you break a twenty?


:huh: ?
Offline Profile Quote Post Goto Top
 
1 user reading this topic (1 Guest and 0 Anonymous)
« Previous Topic · Actionscript · Next Topic »
Add Reply