Skip to main content
Participant
June 17, 2006
Answered

[FlashMX 2004] Problem with an animations random play

Hello,

firstable, I would like to thanks all the peoples that make this forum so interesting.

I found a lot of informations on this site to help me to create my swf that i am working on.

But , at this time I have a problem that i would like to expose to all of you


My swf is quiet simple. I would like show different animations in a random way, with a skeletal
timing. The list of the animations are included in the library of the principal animation.


So I have this principal animation with, on the first frame this code:

_global.MyTime = 5000

//to create a random number between x and y
//Math.round(Math.random()*(y-x))+x;
// so to create a random number between 2 et 7 we will have:
var MaVariable = Math.round(Math.random()*5)+2

trace (MaVariable);
gotoAndPlay(MaVariable);

on the next frames 2 to 7 , I have inserted on each frame one library's animation with a stop().

inside each library's animation , on the first frame, I have the following code:

function GoGet() {
_level0.gotoAndPlay(1);
}
clearInterval(SlideInt);
SlideInt = setInterval(GoGet,MyTime);

on the last frame I have a stop()



So my problem is :

in the beginning everything work fine, but after one minute, before to start the choose librairy's animation, it try to start 2 or 3 other librairy's animations. so in the beginning it's very cautious it just try to start one animation before the one choose, but after 2 minutes it try to start maybee 3 or 4 librairy's animations.

I suppose that my code is not properly set in order.

If somebody could give me infomations, it will help me a lot. i apologize for my bad english.

nb: is it possible to send my .fla on the forum?


This topic is closed to new replies. Start a new post to keep the conversation going.
OrkinCorrect answer
Participant
June 22, 2006
you're welcome.

to shuffle and array add the code below the dotted line to your swf in a location where it's executed before being called. to apply the shuffle() method to an array just use:


Finally I fixed it.

Random

thank u very much kglad , actually i couldn't do that by myself, i learn a lot with your help.

if I can help you for something just contact me.

Bye.

9 replies

kglad
Community Expert
Community Expert
June 22, 2006
you're welcome.
Translate
kglad
Community Expert
Community Expert
June 18, 2006
Math.random() yields a number between 0 and 1. Math.random()*5 yields a number between 0 and 5. Math.round(Math.random()*5) will yield integers between 0 and 5, but will round all numbers, generated by Math.random()*5, from 0 to .5 to 0, from .5 to 1.5 to 1, from 1.5 to 2.5 to 2, from 2.5 to 3.5 to 3, from 3.5 to 4.5 to 4 and from 4.5 to 5 to 5. verstehst?

as for your major problem, post a link to your fla.
Translate
OrkinAuthor
Participant
June 19, 2006
Hy Klagd,

Ja, Ich verstehe... danke schöne.

Here, you will be able to download my fla:

http://www.scube.net/docs/random.fla


I have try different combinations, i still have my problem.

thanx again for your help.



Fla
Translate
kglad
Community Expert
Community Expert
June 20, 2006
you're not clearing an interval somewhere. one of the problems with placing code in different locations in your swf is that it's difficult to debug problems.

remove all the code in you swf (except the stop() in the last frame of your circle movieclips) and use the following on frame one of your _root timeline:

Translate
kglad
Community Expert
Community Expert
June 17, 2006
you have one minor problem (your random number generator creates twice as many 3,4,5 and 6's as it creates 2's and 7's.

the major problem is you're not clearing your SlideInt in GoGet().
Translate
OrkinAuthor
Participant
June 17, 2006
Hy Klagd,
you told me:
"you have one minor problem (your random number generator creates twice as many 3,4,5 and 6's as it creates 2's and 7's."
I don't understand why it should be not equal chance for each number between 2 and 7 to be choose .
Anyway, I was thinking to do it in a non-repetitive way. I 'm gonna use an array to do that.

for my major problem, i tried what you tod me to do by puting the clearing instruction in the GoGet() function, this way:

function GoGet() {
_level0.gotoAndPlay(1);
clearInterval(SlideInt);
}

SlideInt = setInterval(GoGet,MyTime);

But I still I have my problem. :-( Do you have another idea, or perhaps it's a bug of my software.

thanx for your help.

Translate