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

flash actionscript : Load external swfs to play automatically



Shutchinson
5/6/2005 12:00:00 AM
I am trying to get 10 swfs to load and play one after the other without the use
of buttons. I have created an empty mc and of course the first swf loads fine
without any problems.

Does anyone know of a place on the web (I have searched) that will give me
more information as to how to write the ActionScript to get the rest of the
swfs to load one after the other. i know I need to write the trace script, but
other than that, I am completely clueless.
Blade al'Slayer
5/6/2005 12:00:00 AM
[quoted text, click to view]

First of all - here is the place of the web you should search. There are
tons of questions here about loading movies and so on.
Here is what will work, I think:
There are properties of the MovieClip class called _currentframe and
_totalframes. You can load your movie inside an empty movie called
containerMovie and the use something like this:
containerMovie.onEnterFrame = function (){
if (this._cuurentframe == this._totalframes){
// last frame reached
}else {
// do nothig - continue playback
}
}

This will not work if the main timeline of the loaded movie doesn't
reach its end, when the movie ends. If the situation is such you should
place some code in each movie you load that will trigger loading of the
next movie. Something like:
_root.loadNextMovie();
Here _root will be the _root timeline of the host movie and
loadNextMovie will be a function you create to do the unloading of the
previous and load the next movie...

--
jlabsher
5/6/2005 12:00:00 AM
I'm trying to do the same thing. What is this trace script you speak of? Can
you explain it in layman's terms, I've searched for it and it seems pretty
difficult to me. I would think there is some type of onmoviecomplete or
similar command like the onsoundcomplete that would make this possible.
Patrick Bay
5/6/2005 1:20:03 PM
Hi,

Actually, it's not terribly difficult to do this yourself. First, create an
array to hold the names of your clips. Then, create a handler to iterate through
them and load them sequentially. The code (Flash 6/7) will look something like this:

// ----------START CODE ------------

var clipArray:Array=new Array();
clipArray[0]='movie1.swf';
clipArray[1]='movie2.swf';
clipArray[2]='movie3.swf';
clipArray[3]='movie4.swf';
//...and so on.

//And the handler for the loads
var currentLoadItem=1;
var currentLoad:MovieClip=undefined;

//Function to create new clip and start loading
function loadItem(itemNum) {
currentLoad=this.createEmptyMovieClip('movie_'+(itemNum+1), (itemNum+1));
currentLoad.loadMovie(clipArray[itemNum]);
}//loadItem

this.onEnterFrame=function() {
if (currentLoad<>null) {
//Check current loading progress
var total=currentLoad.getBytesTotal();
var loaded=currentLoad.getBytesLoaded();
if ((loaded==total) && (loaded>0)){
//If current clip is loaded and there's
//another in the array, start loading it
if (clipArray[currentLoadItem]!=undefined) {
loadItem(currentLoadItem);
currentLoadItem++;
} else {
//This was the last item. Stop checking.
this.onEnterFrame=undefined;
}// else

}// if
}// if
}//onEnterFrame

//Start loading first item
loadItem(0);

// ----------END CODE ------------

This is not terribly dynamic. It starts loading to specific depths so if there
are existing clips at those depths they will be replaced. Also, the clips all
load on top of each other so you may wish to add some positioning code in there.

Regards,
Patrick

[quoted text, click to view]
Patrick Bay
5/6/2005 1:23:05 PM
Hi,

Yes, in fact there's a handler named onLoad for movie clips. However, I shy
away from using it because it only fires the first time you load a movie. If you
re-load the movie the onLoad handler won't fire and you'll never know that it's
loaded. Have a look at my previous code to see how sequential loading works.
It's not that complicated, simply checking to see the status of the current load
and when it's complete, swap the current load with the next load and repeat.

Regards,
Patrick

[quoted text, click to view]
AddThis Social Bookmark Button