flash actionscript:
Hi all, I am calling a random swf movie out of 11 using the following: choice = Math.round(Math.random()*11); switch (choice) { case 0 : loop_mc.loadMovie("loop0.swf"); break; case 1 : loop_mc.loadMovie("loop1.swf"); break; case 2 : loop_mc.loadMovie("loop2.swf"); break; case 3 : loop_mc.loadMovie("loop3.swf"); break; case 4 : loop_mc.loadMovie("loop4.swf"); break; case 5 : loop_mc.loadMovie("loop5.swf"); break; case 6 : loop_mc.loadMovie("loop6.swf"); break; case 7 : loop_mc.loadMovie("loop7.swf"); break; case 8 : loop_mc.loadMovie("loop8.swf"); break; case 9 : loop_mc.loadMovie("loop9.swf"); break; case 10 : loop_mc.loadMovie("loop10.swf"); break; } loop_mc is just an empty movie clip. I'm trying to add a listener that then calls another random swf from the list, but I can't get it to work. Any ideas?
you can start with: 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; } }; swfA = []; for (var i = 0; i<11; i++) { swfA.push("loop"+i+".swf"); } swfA.shuffle(); dep = 0; currentPlayingNum = 1; currentLoadingNum = 1; this.createEmptyMovie("loop_mc1", dep++); this.loop_mc1.loadMovie(swfA[currentLoadingNum-1]); loopI = setInterval(loopF, 50); function loopF() { var bl = this["loop_mc"+currentLoadingNum].getBytesLoaded(); var bt = this["loop_mc"+currentLoadingNum].getBytesTotal(); if (bl>0 && bl>=bt) { if (currentLoadingNum<10) { if (currentLoadingNum>1) { this["loop_mc"+currentLoadingNum].stop(); } currentLoadingNum++; this["loop_mc"+currentLoadingNum].loadMovie(swfA[currentLoadingNum-1]); this["loop_mc"+currentLoadingNum]._alpha = 0; } } if (this["loop_mc"+currentPlayingNum]._currentframe == this["loop_mc"+currentPlayingNum]._totalframes) { this["loop_mc"+currentPlayingNum]._visible = 0; if (currentPlayingNum+1<11) { var bl = this["loop_mc"+(currentPlayingNum+1)].getBytesLoaded(); var bt = this["loop_mc"+(currentPlayingNum+1)].getBytesTotal(); if (bl>0 && bl>=bt) { currentPlayingNum++; this["loop_mc"+currentPlayingNum]._alpha = 100; this["loop_mc"+currentPlayingNum]._visible = 1; this["loop_mc"+currentPlayingNum].play(); } } else { currentPlayingNum = 1; this["loop_mc"+currentPlayingNum]._alpha = 100; this["loop_mc"+currentPlayingNum].play(); } } }
i don't know if i'm missing something but i get an error message:
Hi try this code.... var myClips:Array = new Array("buzz_teamplay1.swf", "buzz_teamplay2.swf", "buzz_teamplay3.swf", "buzz_teamplay4.swf"); shuffle = function (arr1:Array) { for (i=0; i<arr1.length; i++) { var tmp = arr1[i]; var randomNum = random(arr1.length); arr1[i] = arr1[randomNum]; arr1[randomNum] = tmp; } return (arr1); }; trace("The Ordered Clips !"); trace(myClips); myClips = shuffle(myClips); trace("The Randomised Clips !"); trace(myClips); this.createEmptyMovieClip("bground", 1); bground._x = 0; bground._y = 0; currentClip = 0; function loadNextMovie() { bground.loadMovie("buzzwords/"+myClips[currentClip]); (currentClip<myClips.length-1) ? currentClip++ : currentClip=0; } loadNextMovie(); // Again you have to call the function at each movie clip last frame !
thanks everyone. i did it a different way with flvs. import mx.video.*; var listenUp:Object = new Object(); listenUp.complete = function(eventObject:Object):Void { var randomNum:Number = Math.floor(Math.random()*11); playMovie(randomNum); }; cFLV.addEventListener("complete", listenUp); function playMovie(rand) { cFLV.contentPath = "flvs/flv_"+rand+".flv"; cFLV.play(); } playMovie(Math.floor(Math.random()*11));
Don't see what you're looking for? Try a search.
|