-
1. Re: Script to move playhead randomly to frames?
Ned Murphy Apr 4, 2010 4:09 PM (in response to tacbob)1 person found this helpfulYes, you just need to have a random number generator paired with a gotoAndStop() call as part of a setInterval() scenario.
var intervalID = setInterval(moveToFrame, 8000);
function moveToFrame(){
gotoAndStop(Math.ceil(Math.random()*20));
}
-
2. Re: Script to move playhead randomly to frames?
tacbob Apr 4, 2010 4:15 PM (in response to Ned Murphy)Thank you Sir.
I shall try this tomorrow!!
-
3. Re: Script to move playhead randomly to frames?
Ned Murphy Apr 4, 2010 6:52 PM (in response to tacbob)1 person found this helpfulActually, I forgot that the random function could return a true zero value, which would get you nowhere, so here's an alternate:
var intervalID = setInterval(moveToFrame, 8000);
function moveToFrame(){
gotoAndStop(Math.floor(Math.random()*20)+1);
}
-
4. Re: Script to move playhead randomly to frames?
tacbob Apr 7, 2010 1:30 PM (in response to Ned Murphy)It works very well.
I actually want to create a screensaver type effect so that not only do the images appear at random, their positioning is also anywhere and different each time. Is this possible?
Thank you
-
5. Re: Script to move playhead randomly to frames?
Ned Murphy Apr 7, 2010 3:36 PM (in response to tacbob)You should get familiar with the Math.random() function... hon'st. It's the primary tool used when you want to randomize things, whether it's frame numbers or _x/_y positions or _alpha values or whatever else can be defined by some kind of range of values.
Please mark this posting as answered if you still can.
-
6. Re: Script to move playhead randomly to frames?
tacbob Apr 8, 2010 4:43 AM (in response to Ned Murphy)I understand the Math.random but I am unsure how to move forward with the project now. I do not think I need the previous method anymore (randomly moving to frames). To create a screensaver effect, do I create an empty movie clip that calls in different images, one at a time and positions them in different places using this code?
Thanks
-
7. Re: Script to move playhead randomly to frames?
Ned Murphy Apr 8, 2010 6:57 AM (in response to tacbob)Think about what you want the screen saver to do--I can't determine that for you. If you understand what you can use Math.random() for, then you really should be able to move on and do whatever random thing you are trying to. If you can understand what you want of it, then there is no reason you can't try to create it... just pursue it one step at a time. You'll be much happier with your solution if it's something you created yourself.
-
8. Re: Script to move playhead randomly to frames?
tacbob Apr 8, 2010 10:00 AM (in response to Ned Murphy)var intervalID = setInterval(moveToFrame, 3000);
function moveToFrame(){
gotoAndStop(Math.floor(Math.random()*4)+1);
}I have this script on the first frame of the movie and the script below on each movieclip. I am finding it unreliable - displaying the same twice in a row too often and then time between each image starts getting less.
onClipEvent(load) {
this._x = Math.floor(Math.random() * 800);
this._y = Math.floor(Math.random() * 600);
} -
9. Re: Script to move playhead randomly to frames?
Ned Murphy Apr 8, 2010 2:13 PM (in response to tacbob)1 person found this helpfulAs far as showing the same thing in a row too often, the chances are pretty high that will happen when you only have 4 frames (25% chance... fairly high probability).
As for the time getting shorter, it is most likely because you return to frame 1 every so often and create another interval, so you end up with more than one firing. You need to disallow that code from executing for any return trips to frame 1.
-
10. Re: Script to move playhead randomly to frames?
tacbob Apr 8, 2010 3:16 PM (in response to Ned Murphy)I have no idea how do code this to stop a return to frame 1.
-
11. Re: Script to move playhead randomly to frames?
Ned Murphy Apr 8, 2010 5:52 PM (in response to tacbob)I didn't say to code it so you don't return to frame 1, code it so that when you do return to frame 1 you don't initiate another setInterval... you only want one working. If you put the following code in frame 1 it will take care of that, only allowing one setInterval to be activated...
stop();
var intervalID; // intervalID is undefined here because it has nothing assigned to it
if(!intervalID){ // will only process when intervalID is undefined
intervalID = setInterval(moveToFrame, 3000); // defines intervalID
}function moveToFrame(){
gotoAndStop(Math.floor(Math.random()*4)+1);
}