Groups | Blog | Home
all groups > flash actionscript > june 2006 >

flash actionscript : [FlashMX 2004] Problem with an animations random play


Orkin
6/17/2006 4:40:08 PM
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?



kglad
6/17/2006 5:12:44 PM
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.

Orkin
6/17/2006 10:40:27 PM
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.


kglad
6/18/2006 3:23:16 AM
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.
Orkin
6/19/2006 2:31:48 PM
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.



http://www.scube.net/docs/random.fla
kglad
6/20/2006 1:01:36 AM
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:



playI = setInterval(playF, 3000);
function playF() {
_root.gotoAndStop(Math.ceil(Math.random()*7)+1);
}
Orkin
6/20/2006 9:15:19 PM
So ,

I have done what you told me to do and this is here:

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

but something strange happens, sometimes, one of the circles animations stay
during a long time , actually more than 3000, as it is writing in the code.

So I worked on it and i found a way what work great:

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

So the problem as been resolve by putting the code on the _root timeline, as
you ask me to do. thanx a lot for that kglad!

Has I told you , I was thinking to have random non repetitive by using an
array. I have tried to find some AS code that could help me, but I can't finf
one. do you have an idea on how i could do to random it with a non repetitive
way , with a stop when all the animations have been play one time.

thanx you so much for help kglad .



kglad
6/21/2006 1:42:08 AM
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:



yourArray.shuffle();


-------------------------------------------
Array.prototype.shuffle = function() {
for (var ivar = this.length-1; ivar>=0; ivar--) {
var p = random(ivar+1);
var t = this[ivar];
this[ivar] = this[p];
this[p] = t;
}
};
Orkin
6/22/2006 1:26:28 AM
Finally I fixed it.

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

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.
kglad
6/22/2006 3:30:26 AM
AddThis Social Bookmark Button