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

flash actionscript : Multiple Movies and LoadMovie with onEnterFrame



BrandonCorbin
10/14/2004 8:20:40 PM
Ok here is what I have been working on. Basically a system that you can pass an
array of SWF files. The system will take each swf file, load it, play it, and
when its done it will get the next one in the array. Sounded simple when I
thought of it. I was wrong.

Here is what I am doing.

Creating and Empty Movie Clip,
Loading the Newly created movie clip with an external SWF file. IT LOADS, that
was simple
So when I would try to use the onEnterFrame method to check if the
currentframe is equal to the totalframes it just doesnt do squat

This is where it just doesnt work. Its like the Movieclip object doesnt have
any properties or nuthin! What am I doing wrong here?

Thanks for your help
Brandon

movie_mc.onFrameEnter = function() {
if(movie_mc._currentFrame == movie_mc._totalFrames) {
trace("It should be done");
}
}
_jrh_
10/14/2004 8:32:12 PM
You cannot assign functions/variables/handlers or anything for that matter to a
clip that has not completely loaded, otherwise it will be destroyed once the
clip loads completely.

Don't assign your onEnterFrame function to your clip until you are sure it's
loaded (do a preloader or something to check).
ockley
10/14/2004 8:41:20 PM
Hi.

You could also use a few lines of code to make it happen almost automaticly.

Make a variable in your main document:
var movieEnded:Boolean = true;

movie_mc.onFrameEnter = function() {
if(movieEnded){
// Get the next movie
movieEnded = false;
}

Then you can put this in the last frame of every movie you are using:

_level0.movieEnded = true;
unloadMovie(_root);

FYI. I haven't tried this - Just a thought solution to the problem.

Hope it helps
Karsten
BrandonCorbin
10/14/2004 8:45:18 PM
Ok, so until its loaded the movie can not do a damn thing, well that actually
makes complete sense! So once the movie is loaded then my idea should work.

As far as putting code in each loading movie, I dont think I would want to do
that. I want to keep things as loosely cupeled as possible! Thanks for all of
your help, and I will post any code when I get it working.
BrandonCorbin
10/15/2004 1:18:20 AM
Ok get this. I now have a loader, that is watches and tells me how much of the
external file is loaded. I then have a function that is called with the Load is
complete. With that, I then do a movie_mc.OnEnterFrame = function and spit out
some stuff. However that onEnterFrame is never invoked. Even after the movie
clip is is completely loaded. Any ideas?
BrandonCorbin
10/15/2004 2:26:41 AM
Ok after a few hours of messing around I got it working, its not the cleanest
code, and has yet to be optimized. But it works. Basically you create an array
of swf movies. You then send to the LoadMovies function the array of movies...
and it does the rest, it will start at the first one and then play each one
right after another until it reaches the end of the array. I will be using this
to load up a dynamic XML document with the node of the swf files, and it will
display them dynamically... here is the code. btw thanks for your help. B



// first set of listeners
var myListener:Object = new Object();
var my_mcl:MovieClipLoader = new MovieClipLoader();
myListener.onLoadStart = function(target_mc:MovieClip) {
// trace("*********First my_mcl instance*********");
trace("Your load has begun on movie clip = "+target_mc);
var loadProgress:Object = my_mcl.getProgress(target_mc);
trace(loadProgress.bytesLoaded+" = bytes loaded at start");
trace(loadProgress.bytesTotal+" = bytes total at start");
};
myListener.onLoadProgress = function(target_mc:MovieClip, loadedBytes:Number,
totalBytes:Number) {
trace("*********First my_mcl instance Progress*********");
trace("onLoadProgress() called back on movie clip "+target_mc);
trace(loadedBytes+" = bytes loaded at progress callback");
trace(totalBytes+" = bytes total at progress callback");
};
myListener.onLoadComplete = function(target_mc:MovieClip) {
trace("*********First my_mcl instance*********");
trace("Your load is done on movie clip = "+target_mc);
var loadProgress:Object = my_mcl.getProgress(target_mc);
//trace(loadProgress.bytesLoaded+" = bytes loaded at end");
//trace(loadProgress.bytesTotal+" = bytes total at end");
trace("Current Frame : "+target_mc._currentframe);
trace("total Framesa: "+target_mc._totalframes);
//
checkEnd();
};
myListener.onLoadInit = function(target_mc:MovieClip) {
//trace("*********First my_mcl instance*********");
trace("Movie clip = "+target_mc+" is now initialized");
// you can now do any setup required, for example:
};
myListener.onLoadError = function(target_mc:MovieClip, errorCode:String) {
trace("*********First my_mcl instance*********");
trace("ERROR CODE = "+errorCode);
trace("Your load failed on movie clip = "+target_mc+"\n");
};
// Now load the files into their targets.
// loads into movie clips
this.createEmptyMovieClip("clip2_mc", this.getNextHighestDepth());
this.createEmptyMovieClip("clip1_mc", this.getNextHighestDepth());

//my_mcl.loadClip("http://www.macromedia.com/software/drk/images/box_drk5.jpg",
clip1_mc);
//my_mcl.loadClip("testmovie.swf", clip1_mc);
//my_mc1.loadClip("http://www.macromedia.com/devnet/images/160x160/.jpg",
clip2_mc);
// loads into _level1
//mAIN
//loadMovies(movies);
//my_mcl.addListener(myListener);
var currentPlaying:Number = 0;
my_mcl.addListener(myListener);
movies = new Array();
movies[0] = "testmovie.swf";
movies[1] = "testmovie2.swf";
////
loadMovies(movies);
function loadMovies(movieArray) {

trace("Starting Load Movie Function");
trace("Movie Array Length = "+movieArray.length+" Current Playig =
"+currentPlaying);
trace("Now loading the my_mc1.loadClip("+movieArray[currentPlaying]+",
clip1_mc");
this.createEmptyMovieClip("clip1_mc", this.getNextHighestDepth());
if (currentPlaying == movieArray.length) {
trace("All Movies should be played");
alert("im going to try to stop");
clip1_mc.unloadMovie();

} else {
my_mcl.loadClip(movieArray[currentPlaying], clip1_mc);
}
//my_mc1.loadClip(movieArray[currentPlaying], clip1_mc);
}
//my_mcl.loadClip("testmovie2.swf", clip1_mc);
//
// Second set of listeners
function checkEnd() {
trace("total and currient"+clip1_mc._totalframes+" "+clip1_mc._currentframe);
this.onEnterFrame = function() {
trace("Current: "+clip1_mc._currentframe+" Total: "+clip1_mc._totalframes);
if (clip1_mc._currentframe != 0) {
if (clip1_mc._currentframe == clip1_mc._totalframes) {
trace("We did it baby!");
//this.createEmptyMovieClip(clip1_mc, clip1_mc._depth);
//stop();
currentPlaying = currentPlaying+1;
loadMovies(movies);
}
}
};
}
AddThis Social Bookmark Button