-
array shuffle...
Well im working on this teaser campaign for an event thats happening, and i dont know how to go about setting it up so that when someone comes onto the site, a different clip plays...we have 4 clips, and everytime the person refreshes a different clip comes up...how do i set this up?
-
Ninja Rider
use the random and length functions.
a example
Code:
var my_array:Array = new Array();
my_array.push("one");
my_array.push("two");
my_array.push("tree");
_root.onEnterFrame = function(){
var rand =my_array[Math.round(Math.random()*(my_array.length-1))];
trace(rand);
}
that randomises at the length of the array.
Show me the way to the next whiskeybar ...
-
Thanx for the speedy reply but i dont see any code?
-
Banned
Hi,
The method Jhonte posted will work but it has the possibility of repeating the same random value. In order to prevent repeating values you can splice the currently selected value from the array. This assures it can't be repeated back to back while the movie is playing. However, this wont work for refreshing the page as the array will be refreshed each time, so there will still be a possibility of repeat.
-
Registered User
You can use a Local Shared Object to keep track of the last clip the user watched, and play the next.
Considering you have the clips in the array my_array:
code:
// create the shared object
var my_so = SharedObject.getLocal("LastPlayedSO");
// see if the shared object already exists
if (my_so.data.lastPlayed == undefined) {
// doesn't exist
my_so.data.lastPlayed = 1; // initialize
trace("doesn't exist");
} else if (my_so.data.lastPlayed == 4)
{
// the last played was the last, reset
my_so.data.lastPlayed = 1;
}else {
my_so.data.lastPlayed++;
// exists
// if you test the movie again, this will be triggeres
}
trace('lastPlayed -> ' + my_so.data.lastPlayed);
// play the clip: my_array[my_so.data.lastPlayed-1]
// add your code here
-
thank you so much, but another problem is that i haven't set up my_array, how would i incorporate this into my site.
-
Registered User
That depends on what you want to do. It was you who brought the array in.
My idea is that you can have an array with the names of the movies you want to play.
I corrected and changed the code I posted before. No matter how many elements your array has, you don't have to change anything else.
code:
// array with the movies to play
var my_array = new Array("first.swf", "second.swf", "third.swf");
var numberOfMovies = my_array.length;
// create the shared object
var my_so = SharedObject.getLocal("LastPlayedSO");
// see if the shared object already exists
if (my_so.data.lastPlayed == undefined) {
// doesn't exist
my_so.data.lastPlayed = 1; // initialize
trace("doesn't exist");
} else if (my_so.data.lastPlayed == numberOfMovies)
{
trace("reset");
// the last played was the last, reset
my_so.data.lastPlayed = 1;
}else {
my_so.data.lastPlayed++;
// exists
// if you test the movie again, this will be triggeres
}
trace('lastPlayed -> ' + my_so.data.lastPlayed);
// play the clip: my_array[my_so.data.lastPlayed-1]
// which may correspond to loading the specific movie
loadMovieNum(my_array[my_so.data.lastPlayed-1], 1);
-
Perfect
works great thanx so much
-
this works great so i have exported the videos and made 3 separate flash videos and the main movie witha preloader, only one problem sometimes it goes through all movies in a row and it gets really quirky, is that just because of the preloader? its getting really wacked out.
-
Registered User
hi,
If that happens, it looks like that the preloader is making the movies load repeatdly, which may be because the main movie (the movie which has the code attached to) is being played repeatly, i.e., the code is being triggered more than once.
Posting Permissions
- You may not post new threads
- You may not post replies
- You may not post attachments
- You may not edit your posts
-
Forum Rules
|
Click Here to Expand Forum to Full Width
|