Tek-Tips is the largest IT community on the Internet today!

Members share and learn making Tek-Tips Forums the best source of peer-reviewed technical information on the Internet!

  • Congratulations Chris Miller on being selected by the Tek-Tips community for having the most helpful posts in the forums last week. Way to Go!

Random Flash .swf Movie loader (continuous) 1

Status
Not open for further replies.

markmod1

Technical User
Jul 3, 2007
6
GB
Hi All,

As a newbie I'm trying to solve a little problem I have with a web site flash header i'm creating and bow to your knowledge of using Flash...

I'm using MX and have a header that has a Flash movie in it...this has to be a random one of 47 files...one should load and play randomly and then when this has finished it should load another randomly from the same folder and then that play in full until that has finished and then another.. etc etc

So a random movie loader flash file loading randomly from a single folder containing 47 .swf files called image0.swf to image46.swf (perhaps with a preloader- each swf file is about 27k)

Either this is very simple..or very hard as there is only random loaders on the web which random load images on page refresh (not as a continuous never ending random movies...) and i'm getting square eyes from searching and looking!!

Your help would be greatly appreciated on this..Many thanks in advance....
 
Assuming that you are loading the files into an empty movie clip (empty_mc)

Frame 1 of main movie

function nextRandom(){
empty_mc.loadMovie("image"+random(46)+".swf");
}
nextRandom();

and in the last frame of all 47 swfs add

_parent.nextRandom();


 
Hi thnaks to you both...i'm being really stupid here i have very little knowledge of how to do this... your help is greatly appreciated

My 47 image0 - image 46.swf files sit in a folder and i have created a file called imageloader.swf please can you guide from there simple terms..step by step a little please...tried above and tested movie..got nothing i must be doing something wrong either in creating my empty_mc file? or something else...Thanks for your patience...
 
Bill's solution will work but if you don't want to edit all 47 Flash files to add the code, try this:

I assume you have 47 SWFs in a folder called "swf".
[ol]
[li]Create an empty Flash file "imageloader" just outside the folder[/li]
[li]Place the following script in the Frame 1. It only needs one frame.[/li]
[/ol]
Code:
var mc = this.createEmptyMovieClip("mc", 1);
function nextRandom() {
	var swf = this._url.substr(0, this._url.lastIndexOf("/")+1)+"swf/image"+Math.floor(Math.random()*48)+".swf";
	mc.loadMovie(swf);
}
nextRandom();
this.onEnterFrame = function() {
	if (mc._currentframe>=mc._totalframes) {
		nextRandom();
	}
};
That's all. If you want to take oldnewbie's route let us know - it will require slightly more complex code.

Kenneth Kawamoto
 
Well Kenneth..What can I say your a real flash superhero! That works great!!! I must admit i was dreading adding a frame/action script to the end of all 47 files..sick of the sight of them now even...LOL

However Oldnewbie if you wish to have a look at the . fla its here


and the swf files are here
and are numbered image0.swf to image46.swf

Thanks again to both of you for your superb help..it was becoming a realllllllyyyyy long day to try and sort this.
 
The various files can tak a while to load between the different swf files before they are loaded and cached...is it possible to preload them simply?
 
I haven't looked at your FLA but here's the modified script which preloads all 47 SWFs at the beginning into individual MovieClips then swap them around at random - this should eliminate the time lag completely:
Code:
//AS1
for (var i = 0; i<=46; i++) {
	var mc = this.createEmptyMovieClip("mc"+i, i+1);
	mc._x = -1000;
}
var isPreloadDone = false;
var i = 0;
function preload() {
	if (i<=46) {
		trace("preloading "+i);
		var swf = this._url.substr(0, this._url.lastIndexOf("/")+1)+"swf/image"+i+".swf";
		this["mc"+i].loadMovie(swf);
		i++;
	} else {
		isPreloadDone = true;
		nextRandom();
	}
}
preload();
var currentMC;
function nextRandom() {
	if (currentMC) {
		currentMC._x = -1000;
		currentMC.stop();
	}
	var mc = this["mc"+Math.floor(Math.random()*47)];
	trace(mc);
	mc._x = 0;
	mc.gotoAndPlay(1);
	currentMC = mc;
}
this.onEnterFrame = function() {
	if (!isPreloadDone) {
		if (mc.getBytesLoaded()>=mc.getBytesTotal()) {
			mc.stop();
			preload();
		}
	} else {
		if (currentMC._currentframe>=currentMC._totalframes) {
			nextRandom();
		}
	}
};

Kenneth Kawamoto
 
FANTASTIC !!!!

Kenneth you're a real Flash star! This has helped me complete a project...I'm real happy that there is still guys (and most probably girls too) out there who have the same ethic as me..if you help someone when you can, there will be always someone there to help you when you need it. Cheers again...ps love your website VERY SPECIAL...NICE FLASH WORK!
 
Status
Not open for further replies.

Part and Inventory Search

Sponsor

Back
Top