Tek-Tips is the largest IT community on the Internet today!

Members share and learn making Tek-Tips Forums the best source of peer-reviewed technical information on the Internet!

  • Congratulations gkittelson on being selected by the Tek-Tips community for having the most helpful posts in the forums last week. Way to Go!

randomizer

Status
Not open for further replies.

Flashoid

Technical User
Dec 11, 2002
163
US
Not sure if I am on the right track or not even close. I have this code in frame 1 in root timeline:

gotoAndStop (random (6)+1);

I have 6 movieclips created with nothing in frame one except a stop action script and in frame 2 another stop action script with another movieclip that plays an animation. These movieclips are labeled mc1, mc2, mc3, mc4, mc5, mc6.

I have a button in frame 1 in the root timeline with this code:

on (press) {

ran = random(6)+1;
tellTarget (("/mc") + ran) {
play ();
}

Currently when you push the button it occassionally will randomly play one of the 6 MCs but usually requires pressing the button several times for it to advance to the next MC. I want it to randomly access one of 6 MC's and goto frame 2 each time you press the button.

Does anyone have any insight into what I am doing wrong or another approach?

thanks!!
 
Using random doesn't mean the random number will be unique...
The same number can be randomly called for 4, 5 or emen more times in a row...

Add a trace statement to see what number does come up...

ran = random(6)+1;
tellTarget (("/mc") + ran) {
trace("Random Number: "+ran;
play ();
}

Regards. FLASH HELP - OPENED FOR BUSINESS!
TO GET YOUR OWN FREE WEBSITE HOSTING
 
I couldn't get the trace to show any numbers - just showed this:

Random Number:

It's ok if it plays the same MC multiples times in a row, I'd just like it to play one of the 6 MC each time I click the button. So far it only intermittently plays MCs.
 
I also tried this but having no success either:

Button code:

on (press) {

ran = random(6) + 1;
ranName = "myNumber" add ran;
trace (eval(ranName));

tellTarget (("/mc") + ran) {
play ();
}

}

code in frame 1:
myNumber = random(5);
trace (myNumber);


the trace only displays undefined whenever you click on the button.
 
Flash 8 and publishing the file to flash v6.
 
I am basically trying to create a Wheel of Fortune game whereas each time you click a Spin button it spins an arrow around randomly and lands on a different part of the wheel each time. I know Ran is old AS but I haven't been able to get math.random to work either. Any help would be appreciated!
 
I get this error when I run that script:

**Error** Scene=Scene 1, layer=MCs, frame=1:Line 4: ')' or ',' expected
trace("Random Number: "+ran;

Total ActionScript Errors: 1 Reported Errors: 1


I've tried putting in different things but can't make it publish.
 
I put this in for the button code:

on (press) {var ran:Number;
ran = random(6)+1;
tellTarget (("/mc") + ran) {
trace("Random Number: ") +ran;
play ();
}


But the output box only displays this over and over again:


Random Number:
 
Any chance I could email you my fla? I don't know if I am close to it working or if it's never going to happen with the track I'm on.
 
Thanks! I will send it out to you to see what you think.

 
Status
Not open for further replies.

Part and Inventory Search

Sponsor

Back
Top