Groups | Blog | Home
all groups > flash actionscript > october 2005 >

flash actionscript : Play Movies once in a random order?


Chris Goodiel
10/20/2005 7:51:46 PM
I have a map that my client wants their locations(21) to glow in a random
order.

How I have the flash set up now is the map graphic on one layer and 21
instances of a movie. Being new to action script and coding for that matter I
have no clue how to have these movies play one at a time in a random order
until all are played then start over in a random order.

Is this possible?

Thanks a bunch for yoru help.

Chris Goodiel
kglad
10/20/2005 8:00:55 PM
yes. give each of your 21 movieclips an instance name and list them in an
array:

yourMCA=[mc1,mc2,...,mc21];

use an array shuffle to randomize these movieclips and then start playing the
first using a loop to check when it's done playing and start the next. below
is an array shuffle method:

Array.prototype.shuffle = function() {
for (var ivar = this.length-1; ivar>=0; ivar--) {
var p = random(ivar);
var t = this[ivar];
this[ivar] = this[p];
this[p] = t;
}
};
iamalex
10/5/2006 2:14:31 AM
I have various movies, all separate swf's. Can you help me to play all of them
in one container one after the other, making sure they all finish before next
one loads.

Would desparately appreciate help.

alex
kglad
10/5/2006 4:04:46 AM
list your swfs in an array, shuffle the array and load them sequentially:



Array.prototype.shuffle = function() {
for (var ivar = this.length-1; ivar>=0; ivar--) {
var p = random(ivar);
var t = this[ivar];
this[ivar] = this[p];
this[p] = t;
}
};

swfA=["swf1.swf","swf2.swf",...,"lastswf.swf"]; // <- customize to match
your swf names. nothing else needs editing.

lo=new Object();
lo.onLoadInit=function(targ){
targ.onEnterFrame(){
if(this._currentframe==this._totalframes){
index++;
if(index<swfA.length){
mcl.loadClip(swfA[index],targ);
} else {
delete this.onEnterFrame;
// they've all loaded. reset index to zero and use
mcl.loadClip(swfA[index].targ) if you want to restart.
// call swfA.shuffle() if you want to re-randomize your swfA().
}
}
}
}
swfA.shuffle();
index=0;
mcl=new MovieClipLoader();
mcl.addListener(lo);
mcl.loadClip(swfA[index],targ);
iamalex
10/5/2006 3:49:27 PM
kglad,

I took off shuffle, is attached correct and put code in empty fla movie.

Getting Syntax error on line 15 ---targ.onEnterFrame(){

Opens to empty screen.

Also, to have this loop continuously until exited, how do I do that?

Please help again. I would so appreciate your help.

Alex

//Array.prototype.shuffle = function() {
Array.prototype = function() {
for (var ivar = this.length-1; ivar>=0; ivar--) {
var p = random(ivar);
var t = this[ivar];
this[ivar] = this[p];
this[p] = t;
}
};

swfA=["slide1.swf","slide2.swf","slide3.swf","slide4","slide5.swf"]; // <-
customize to match your swf names. nothing else needs editing.

lo=new Object();
lo.onLoadInit=function(targ){
targ.onEnterFrame(){
if(this._currentframe==this._totalframes){
index++;
if(index<swfA.length){
mcl.loadClip(swfA[index],targ);
} else {
delete this.onEnterFrame;
// they've all loaded. reset index to zero and use
mcl.loadClip(swfA[index].targ) if you want to restart.
// call swfA.shuffle() if you want to re-randomize your swfA().
}
}
}
}
//swfA.shuffle();
swfA();
index=0;
mcl=new MovieClipLoader();
mcl.addListener(lo);
mcl.loadClip(swfA[index],targ);
kglad
10/5/2006 4:21:44 PM
that should be:



MichelleTen
10/5/2006 5:02:58 PM
I am actually trying to do the same thing only I'm not using imported swf
files i just want to attach the movie clips. Would i use this same code? i
really have no idea as to how to actionscript. I also don't need it to be
continuous. I just need for it to play through the movie clips once and stop.
kglad
10/5/2006 5:55:46 PM
michelle, you can use the following. be sure you use your linkage ids in the
mcA() array. (ie, right click on your library movieclips, click linkage, tick
export for actionscript, enter an id name in the box -and in the array- and
click ok.)



mcA = ["mc1ID", "mc2ID", "mc3ID"];
index = 0;
this.attachMovie(mcA[index], "mc", 1);
mc.onEnterFrame = function() {
trace(this._currentframe);
if (this._currentframe == this._totalframes) {
index++;
if (index<mcA.length) {
_parent.attachMovie(mcA[index], "mc", 1);
} else {
this.removeMovieClip();
}
}
};
kglad
10/5/2006 8:12:15 PM
i see a white rotating box, another white one, then a red.

post a link to your file.

use an empty movieclip to more easily postion your loaded swf.

and yes, you can put fscommands in your onLoadInit() handler or you can put it
in your external swfs.
iamalex
10/5/2006 9:09:06 PM
I'll have to play with it tonight and let you know tomorrow. The actual slides are to big to post on web.
Thank you so much for help so far.

iamalex
10/6/2006 1:08:05 AM
I tried some more, but still only get one slide to load.
Put up the sample file again at:

ftp://MAImisc.mai-stl.com:plum@ftp.business.earthlink.net

Can you please look at files and let me know what I am doing wrong.

Thanks,

Alex
kglad
10/6/2006 2:38:03 AM
iamalex
10/6/2006 2:57:27 AM
I have publish for flash 8 and actionscript2

Any other thoughts? I'm on laptop now, so diff computer and works on neither.

Thanks,

kglad
10/6/2006 4:46:04 AM
iamalex
10/6/2006 1:13:38 PM
It fails to load in flash test environment and browser, both.
Maybe I still have something set wrong???? If it works for you, does not make sense.
I have to get this figured out.

Thanks,

iamalex
10/6/2006 1:53:36 PM
for reference, I am on windows xp
flash version 8
in flash selected:
version = 8
load = bottom up
actionscript2
compress movie

container will be exe and run movies from there, but tried in html and exe and
swf, only first movie loads
kglad
10/6/2006 2:48:30 PM
iamalex
10/6/2006 4:02:15 PM
Yes, that's it. It works.

I owe you big time.

Thanks kglad,

iamalex
10/6/2006 6:02:44 PM
kglad,

One other thing, sorry. How do I keep it on a continous loop instead of going blank when done?

iamalex
10/6/2006 6:22:01 PM
kglad
10/6/2006 11:50:42 PM
AddThis Social Bookmark Button