View Full Version : Loading multiple .swf's -- Class Project
stephenslm
01-13-2006, 03:56 PM
I am sure that this has already been discussed here, but we are in a pickle and needed some help. For a project, we have created several .swfs. We woud like to know, with action script or some other method, how we might load all the external swf's before the movie plays and then play them in a certain order.
ex. load-> swf1,swf2,swf3,swf4,swf5
play-> swf1,swf2,swf3,swf4,swf5
If a "play" button could be used to start the playing sequence would be nice also.
sophistikat
01-13-2006, 04:05 PM
this issue has been covered many times so let me ask you
do you know how to preload just one external movie?
are you comfortable with arrays?
can you explain this in more detail: "play them in a certain order"
mc2 plays > when its over > mc1 plays > when its over > mc3 play etc.etc.
stephenslm
01-13-2006, 05:11 PM
What we had in mind, was that they are all loaded together and the start, and maybe at like a menu, the click of a "play" button would begin the movie. What we were hoping is that we could play mc1 > when its over > mc2 > when its over > mc3..etc without load times inbetween the movies. We do know how to load one swf into a mc on the stage.
sophistikat
01-13-2006, 06:16 PM
Frame 1
stop();
// array of your movieclips
var $mcs = ["mc1.swf", "mc2.swf", "mc3.swf", "mc4.swf"];
// count is to know who to load from our $mcs arrays
var $count = 0;
// preloader function
function preloader () {
// set the mc variable to our current movie & create a placeholder
var mc = this.createEmptyMovieClip("mc" + $count, this.getNextHighestDepth();
mc._x = 0; // set its _x position
mc._y = 0; // set its _y position
mc._visible = false; // set its _visible state
// load the first swf into our mc
mc.loadMovie ($mcs[$count]);
// preload loop
this.onEnterFrame = function () {
// get the total percent of our current movieclip
Percent = Math.ceil ((mc.getBytesLoaded () / mc.getBytesTotal ()) * 100);
// if Percent is a number
if (!isNaN (Percent)) {
// probar is your preload movieclip, txtfield is the instance name of your dynamic textfield
probar.txtfield.text = Percent + "%"
probar._visible = true;
}
// if Percent, of the current movie, has reached 100
if (Percent == 100) {
// delete the loop
delete this.onEnterFrame;
// increase our count by one
$count++;
// check if all movies has been loaded
if ($count != $mcs.length) {
// not done
// load the next movie
preloader ();
} else {
// done!
// next frame
gotoAndStop(2);
}
}
};
}
// start the preloader
preloader();
Frame 2
// your play button
play_btn.onRelease = function () {
// make the first movieclip visible
mc1._visible = true;
// begin playing its timeline
mc1.gotoAndPlay(1);
// disable this button
this.enabled = false;
}
All SWFs
// first and last frame of each movie
stop();
// mc1.swf
// add this action to the last frame of each movieclip
_parent.mc1._visible = false;
_parent.mc2._visible = true;
_parent.mc2.gotoAndPlay(1);
// mc2.swf
// add this action to the last frame of each movieclip
_parent.mc2._visible = false;
_parent.mc3._visible = true;
_parent.mc3.gotoAndPlay(1);
// mc3.swf
_parent.mc3._visible = false;
_parent.mc4._visible = true;
_parent.mc3.gotoAndPlay(1);
// mc4.swf
_parent.mc4._visible = false;
_parent.mc1._visible = true;
_parent.mc1.gotoAndPlay(1);
/* THESE ACTIONS WILL LOOP THROUGH ALL MOVIECLIPS */
stephenslm
01-13-2006, 07:59 PM
thanks a lot sophistikat. Srry if my question was a regular post on here..
sophistikat
01-13-2006, 08:02 PM
np, let me know what grade we get :D
smithwa
01-18-2006, 03:34 PM
Hey there, I was trying to run this code and was able to get everything working, but you can actually see the swf's when they finish loading on the progress bar page. I need to somehow hide the individual swf's when they finish loading while the rest of the swf's load. I would greatly appreciate any advice on how to hide the loading files. Thanks, Alex
johnnyboy
01-18-2006, 04:22 PM
Did you remember to do all this... with the first and the last frame thing.
// first and last frame of each movie
stop();
// mc1.swf
// add this action to the last frame of each movieclip
_parent.mc1._visible = false;
_parent.mc2._visible = true;
_parent.mc2.gotoAndPlay(1);
// mc2.swf
// add this action to the last frame of each movieclip
_parent.mc2._visible = false;
_parent.mc3._visible = true;
_parent.mc3.gotoAndPlay(1);
// mc3.swf
_parent.mc3._visible = false;
_parent.mc4._visible = true;
_parent.mc3.gotoAndPlay(1);
// mc4.swf
_parent.mc4._visible = false;
_parent.mc1._visible = true;
_parent.mc1.gotoAndPlay(1);
/* THESE ACTIONS WILL LOOP THROUGH ALL MOVIECLIPS */
smithwa
01-18-2006, 05:04 PM
Yes, I did all of that. That only hides the swf's when they are actually playing after being loaded. My problem is actually during the loading.
johnnyboy
01-18-2006, 05:09 PM
Try loading all og the external SWFs into a container, and set the container to _visible = false; until the bunch is loaded
smithwa
01-18-2006, 05:15 PM
That is actually what sophistikat's preloader function does. it creates a container to load the swf's into and sets the container's visibility to false. The swf's just play on top of the invisible container. Here is what I've found out so far though. I could insert a blank frame at the beginning of each swf, i was just looking for a more professional way of doing it i guess.
johnnyboy
01-18-2006, 06:29 PM
yes, but try defining your container outside the function...
stop();
this.createEmtyMovieClip("container_mc", this.getNextHighestDepth());
this.container._visible = false;
function ()...
...
container.createEmtyMovieClip("mc" + $count, container.getNextHighestDepth());
....
if (Percent == 100) {
// delete the loop
delete this.onEnterFrame;
// increase our count by one
$count++;
// check if all movies has been loaded
if ($count != $mcs.length) {
// not done
// load the next movie
preloader ();
}
else {
// done!
this.container._visible = true;
}
sophistikat
01-19-2006, 11:24 PM
hi smithwa , i was helping someone else out with a similar problem and i made this example for them, i hope this helps you out.
|
vBulletin® v3.8.5, Copyright ©2000-2012, Jelsoft Enterprises Ltd.