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 strongm on being selected by the Tek-Tips community for having the most helpful posts in the forums last week. Way to Go!

LoadMovie Causing Projector file to Lag 1

Status
Not open for further replies.

dmears1

Technical User
Jun 18, 2003
208
US
I have a flash projector file which is loading in 2 xml files: one containing text only, the other containing URL to both SWF & image files. This projector runs pretty much 24/7. We are running into issues where after 2-3 days the projector files starts lagging when loading in the images and/or swf files. The actionscript loops through the XML file and uses loadMovie to load the images/swfs into an empty movie clip. Every 15 seconds it loads the next image in the XML file into the movie clip.
Is there a more efficient way to load the external images into the projector?

Code:
delay = 15000;
function loadXMLAds(loaded) {
	if (loaded) {
		xmlNode = this.firstChild;
		image = [];
		total = xmlNode.childNodes.length;
		j = 0;
		for (i=0; i<total; i++) {
			image[j] = xmlNode.childNodes[i].childNodes[1].firstChild.nodeValue;
				j++;
		}
		arrTotal = image.length;
		firstImage();
	}
}
function firstImage() {
	picture.loadMovie(image[0], 1);
	slideshow();
}
function slideshow() {
	myInterval = setInterval(pause_slideshow, delay);
	function pause_slideshow() {
		clearInterval(myInterval);
		if (p == (arrTotal-1)) {
			p = 0;
			firstImage();
		} else {
			nextImage();
		}
	}
}
p = 0;
function nextImage() {
	if (p<(arrTotal-1)) {
		p++;
		picture.loadMovie(image[p], 1);
		slideshow();
	}
}
 
One thing you may want to try is instead of loading image/SWF every 15 seconds, when you parse the XML create as many empty MovieClips as in the XML and load all the images/SWFs in individual MCs, then every 15 seconds bring the MC on Stage in turn.

Kenneth Kawamoto
 
Thanks for the tip Kenneth. I'll give it a try and post back with an update.
 
Follow Up Question:
Is there a way to control the main timeline on an external swf if I have no way of knowing the any instance names in the external swf?

The updated code is as follows:
Code:
delay = 15000;
function loadXMLAds(loaded) {
	if (loaded) {
		xmlNode = this.firstChild;
		image = [];
		total = xmlNode.childNodes.length;
		j = 0;
		for (i=0; i<total; i++) {
			image[j] = xmlNode.childNodes[i].childNodes[1].firstChild.nodeValue;
				j++;
		}
		arrTotal = image.length;
		for (k=0; k<arrTotal; k++) {
			_root.createEmptyMovieClip("ad"+k, k+100);
			_root["ad"+k].loadMovie(image[k]);
			_root["ad"+k]._x = 1138.9;
			_root["ad"+k]._y = 260;
			_root["ad"+k]._alpha = 0;
		}
		firstImage();
	}
}
function firstImage() {
	_root["ad"+p]._alpha = 100;
	_root["ad"+(p+(arrTotal-1))]._alpha = 0;
	slideshow();
}
function slideshow() {
	myInterval = setInterval(pause_slideshow, delay);
	function pause_slideshow() {
		clearInterval(myInterval);
		if (p == (arrTotal-1)) {
			p = 0;
			firstImage();
		} else {
			nextImage();
		}
	}
}
p = 0;
function nextImage() {
	if (p<(arrTotal-1)) {
		p++;
		_root["ad"+p]._alpha = 100;
		_root["ad"+(p-1)]._alpha = 0;
		slideshow();
	}
}
In my firstImage() and nextImage() functions I need to tell the movieclip to gotoAndPlay(1), something like:
Code:
_root["ad"+p].gotoAndPlay(1);
 
The name of the external SWF has no meaning once loaded into a MovieClip: the root timeline of the external SWF becomes the root timeline of the MovieClip loading it. So, your gotoAndPlay() command is the right way.

Kenneth Kawamoto
 
The issue I'm running into is that the external swfs I'm loading in have several frames w/stop commands in their last frames. Once I've loaded them into the empty movieclips, they play once and then stop.

When the parent movie loops through the movieclips (using the the firstImage() & nextImage() functions) the external swfs are loading but not playing, they are stuck on the last frame.
 
Thanks for all the help Kenneth. I've tried gotoAndPlay(1), nextFrame(), play(), all out of desperation. None are working. Here's an example of how I'm using them:
Code:
function firstImage() {
	_root["ad"+p].gotoAndPlay(1);
	_root["ad"+p]._alpha = 100;
	_root["ad"+(p+(arrTotal-1))]._alpha = 0;
	slideshow();
}
 
Put [tt]trace()[/tt] to see what's happening - e.g.;
Code:
function firstImage() {
   var mc = this["ad"+p];
   mc.gotoAndPlay(1);
   mc._alpha = 100;
   trace(mc);
   trace(mc._currentframe);
   this["ad"+(p+(arrTotal-1))]._alpha = 0;
   slideshow();
}

Kenneth Kawamoto
 
It shows I'm in frame 1 of each of the movieclips.
For example:
MovieClip: _level0.ad0
Frame #: 1
MovieClip: _level0.ad1
Frame #: 1
MovieClip: _level0.ad2
Frame #: 1

I thought that the root timeline for the movieclip would be the same as the root of the external swf.
 
> I thought that the root timeline for the movieclip would be the same as the root of the external swf.

Yes that's right. Your trace is showing that your external SWF is at the frame 1.

Do you have child timelines in the external SWFs?

Kenneth Kawamoto
 
I am guessing so. The external SWFs are ads which are created by someone else. I only receive the SWF with no other info relating to them.
 
Oh dear... Why people nests MovieClips for no reason is beyond me. If you do "Debug Movie" you'll see if they have nested timelines.

But if that's the case the approach I suggested won't work as there's no way to reset those SWFs to play from the beginning apart from reloading them.

Kenneth Kawamoto
 
Thanks for all the help. I will have to look for a different solution.
 
Status
Not open for further replies.

Part and Inventory Search

Sponsor

Back
Top