View Full Version : goto And Play random frame ??
jepezi
January 7th, 2003, 05:04 AM
Ok. I have a 30-frames mc,each frame has a logo of my client. I want visitors see 30 logos randomly and each logo will pause 2 seconds for viewing. How can I do it?
any help would be appreciated.
eilsoe
January 7th, 2003, 06:20 AM
well.. one way of doing it is:
onClipEvent(enterFrame){
i++;
if(i==(fps*2){
this.gotoAndStop(Math.round(Math.random()*30));
i=0;
}
}
the "fps*2", is just your current fps times 2, insert a number instead. :)
This is not the best way to do it, cuz if the viewer has a slow pc, it'd take longer to count the i. so they'd have to wait maybe 4-5 seconds.. :-\
but a better way would be to set up intervals, can't remember how...
pom
January 7th, 2003, 10:08 AM
http://www.kirupaforum.com/showthread.php?s=&threadid=7457
Guig0
January 7th, 2003, 10:27 AM
how about change in this thread
http://www.kirupaforum.com/showthre...=&threadid=7457
those lines:
One good solution is to write the title like that:
[FMX]Arg!! Desperate!! need help please!!
[F5]Arg!! For Actionscript Guru!! Beginner needs help!
to:
One good solution is to write the title with a short description of your problem preceeded by the Flash Version between brackets, like this:
[FMX]goto And Play random frame ??
[F5]Random Generator
That way the helper will have a preview of what is inside the thread, know what I mean?;)
What do ya think?
[EDIT]Typos
senocular
January 7th, 2003, 11:32 AM
hahahaha thats the first thing I thought when I first read ilyaslamasse's post originally when I first found this forum. It gave me quite a giggle :)
btw, as for the question, if using MX, setInterval may be the way to go. And if you dont want them to repeat, make an array of frames and take randomly from that until gone
// logo clip
logoClip = _root.presentation.logos;
// array of frames
frames = [];
for(i = 0; i < logoClip._totalframes; i++) frames[i] = i;
// function to go to a random frame (logo)
nextLogo = function(){
if (len = frames.length) logoClip.gotoAndStop(frames.splice(random(len),1)) ;
else whenDone();
}
// called when all frames are played
whenDone = function(){
trace("done");
clearInterval(logoTimer);
}
// call once to start
nextLogo();
// set interval to nextLogo every 2 seconds
logoTimer = setInterval(nextLogo, 2000);
jepezi
January 7th, 2003, 09:39 PM
[I use FMX]Thank you very muchhhhhh , senocular!!!
you save my life. I tried many ways I could do until I almost reached my goal but I found that the first logo weren't shown randomly but always first frame of logoClip instead. I can not figure out why it was.
this is my code at 1st frame of main timeline:
nums = "";
k=1;
nofNums = 30;
range = 30;
numsSoFar = 0;
showNums = new Array();
while (numsSoFar<nofNums) {
aNum = parseInt(Math.random()*range);
if (nums.indexOf("@"+aNum+"@") ==-1) {
nums +="@"+aNum+"@";
showNums[numsSoFar++] = aNum;
}
}
second frame:
// I place the logoClip here and put this on it
onClipEvent(load){
this.gotoAndStop(showNums[0]);
}
20th frame:
mc.gotoAndStop(showNums[k++]);
gotoAndPlay(2);
anyway,Thank you very much! though I still don't understand some parts of your code but I will study it again when I finish my work.
thoriphes
January 8th, 2003, 12:28 AM
i usually just do...
gotoAndPlay(random(_totalframes)+1);
...in one of the frames.
lostinbeta
January 8th, 2003, 12:38 AM
random was deprecated with MX, it would now be...
gotoAndPlay(1+Math.random()*_totalframes);
Also... this code is too short... it is not accepted here!!!! :scream:
LOL, just kidding man, this is the same method I use for random frames too.
senocular
January 8th, 2003, 07:21 AM
Originally posted by lostinbeta
random was deprecated with MX, it would now be...
gotoAndPlay(1+Math.random()*_totalframes);
random was deprecated with 5 and gotoAndPlay will not always work with non integer floats ;)
*cough*
btw, random() is much much faster and still works, so use it
*cough*
pom
January 8th, 2003, 09:19 AM
Originally posted by senocular
*cough*btw, random() is much much faster and still works, so use it *cough* *cough*I have to agree with that*cough*
And Guig0, I know, it was ironic. :beam:
lostinbeta
January 8th, 2003, 12:46 PM
BAH, if it is faster than why was it deprecated!?!?!?
Man, I always learn the slow way ;)
And I didn't mean to say <B>with</B> MX, I meant to say <B>in</B> MX, I have no idea what is deprecated and what isn't in Flash 5. (in my defense ;))
senocular
January 8th, 2003, 12:50 PM
just to be more ECMA-262 compliant :-\
and you meant is and not was too, right? :beam:
pom
January 8th, 2003, 12:51 PM
I don't what are the criteria for deprecation (???) but I've always heard that the older the code, the faster. Well, maybe not Flash 2 code...
senocular
January 8th, 2003, 12:58 PM
Originally posted by ilyaslamasse
I don't what are the criteria for deprecation (???) but I've always heard that the older the code, the faster. Well, maybe not Flash 2 code...
yeah, thats true for everything. The Flash 5+ syntax you are used to is mostly (all new syntax that is... new methods and classes etc) written in Flash actionscript internally, a lot of times just wrappers of Flash 4 methods. This being the case, its pretty obvious to assume Flash 4 methods are infact faster.
lostinbeta
January 8th, 2003, 01:07 PM
:scream:
Well that sucks, I guess I gotta go back and learn all the Flash 4 code now :angry: :bad:
senocular
January 8th, 2003, 01:34 PM
Chances are you'll never notice a difference in performance. Only really script heavy projects would benefit from it. On a regular-use basis, its nothing to worry about. Even then the main cause of slowdown if any is simple visual frame refresh. :)
lostinbeta
January 8th, 2003, 01:44 PM
Well if ever I get good enough at actionscript to do some heavier stuff (haha, I kid myself so) I now know that old syntax is faster..... that is a good thing to know.
pom
January 8th, 2003, 08:38 PM
Well, you also have to consider the amount of code you have to use. random may be faster than Math.random, but this is just a function to function comparison. If you're involved in "heavier stuff", well, you just can't get heavy with Flash 4 :P
thoriphes
January 9th, 2003, 12:59 AM
yeah, have you guys ever tried the Math.sqrt() function to find a square root of a function?
i once had a movie that used the distance formula on each enterFrame and it was killing my CPU. i traced it all the way back to that function.
pom
January 9th, 2003, 06:04 AM
Yep, true, that's why I now compare squared distances. It proves really faster :)
senocular
January 9th, 2003, 08:37 AM
Originally posted by ilyaslamasse
Yep, true, that's why I now compare squared distances. It proves really faster :)
ok just for anyone who doesnt know what ilyaslamasse means by that... heh "squared distances" is taking the number you would normally compare to Math.sqrt(value) and squaring it manually so you would only have to compare it to that value without the Math.sqrt()
ex:
if (Math.sqrt(x) == 5) then ....
would become
if (x == 25) then ...
Basically you are squaring both sides of the equation (to maintain equality) but to also get rid of the sqrt. Because you do the number in your head (or using a claculator ;) thats one less thing that Flash has to do...
if (Math.sqrt(x)² == 5²) then ....
gives
if (x == 25) then ...
And that second example is much much faster for Flash to resolve
(just for any onlookers of the tread :))
Powered by vBulletin® Version 4.1.10 Copyright © 2012 vBulletin Solutions, Inc. All rights reserved.