first post.
um ok i need some help here with my patchy scripting.
Is it possible for a main clip to figure out if an external clip is fully loaded
(no loading bars or info required) and then perform an action in the main timeline? and then once that extenal clip has finished playing to make the main clip again perform another action?
If anyone knows of any tutorials i can get my teeth in, it would be very much appreciated. Or if someone could post some code that would be even better.
I myself do not know how to do this, but I think you’re gonna be using if statements. You might want to look that up… it just sounds like what would be used here.
I know I wasn’t much help but I hope I gave you something to go by.
look up the commands global and localconnection in the actionscript dictionary i would like to help you but i’m learning these things if i get the code i’ll post it.
hey thanks for the replies.
i have used a typical preloader targeted at the mc where the external mc loads into but it doesn’s work, (and i dont want an external preloader since the loading of the external swf should take place in the background).
I came across a tutorial here on kirupa about Listeners and Broadcasters and come to think of it that would be ideal, especially if I could setup 1 listener for many different mc’s that broadcast a different message when loaded/unloaded.
I do need to find a tutorial though that focuses more on the onLoad/unLoad event since i’m not dealing with buttons but rather with mc’s.
hi naderslim, thanks for the code.
the external swf’s are individually published and loaded in the main clip using loadmovie, into an empty mc.
so far i’ve read afew tutorials on broadcasters and listeners and although got it to work within the main clip i don’t think it works with external clips being loaded into the main clip.phew. In other words i can’t get a seperate external ‘child’ clip to broadcast an event (i.e ‘loaded’) to a listener in the main 'parent ’ clip in order to invoke an action in the same parent clip.
I have a much easier way, you don’t need to use anything like “broadcasters and listeners”.
Create an empty movieClip and place it on your main movie.
use loadMovie(“filename.swf”, “placeHolder”), placeHolder will be the empty movieClip that you previously created. Lets give the placeHolder a name, lets say “emptyMC”.
use “if else statement” on your main movie, on one of the keyframes;
this.onEnterFrame = function(){
if(emptyMC._getBytesLoaded == emptyMC.getBytesTotal){
//put watever action here.
delete this.onEnterFrame;
}
}
If you want to check whether the external movie had finished playing,
Place a code at the first keyframe of your external movie, create a variable;
externalMovieLoaded = false;
Place a code at the last keyframe of your external movie;
externalMovieLoaded = true;
On your main movie use this code on any keyframe;
this.onEnterFrame = function(){
if(emptyMC.externalMovieLoaded == true){
//put watever action here.
delete this.onEnterFrame;
}
}
That should give you the answer to your qn.
Hope it helps
though this is a tried and true way of monitoring loaded clips, the MovieClipLoader class if far more functional and efficient. Broadcasters and listeners are great but mainly used for monitoring a change in value of a property of the object that is broadcasting. Macromedia created the MOvieclipLoader class so you wouldn’t have to use broadcast and listeners for loading mechanisms. If you are working with AS1 and player 6 then you can use Colin Moock’s QLOader which you can download from here…
Both Moock’s class and Macromedia’s class work the same way, with minor syntax differences in the way you call the load function…here is an example of colin moock’s:
#include "com.qlod.LoaderClass.as"
//be sure to place the as file in the same directory as your fla
myloaderObj = new com.qlod.LoaderClass();
myListener = {};
myListener.onLoadStart = function (loaderObj) {
//place code here to run as soon as the movie starts to load
};
myListener.onLoadProgress = function (loaderObj) {
//this function acts like an onenterframe function, repeatingly
//called as the movie loads in.
//place code here to run while the movie is loading, for eg.
_root.myLoaderBar._xscale = loaderObj.getPercent();
_root.myTextField.text = loaderObj.getPercent() + "%";
};
myListener.onLoadComplete = function (loaderObj) {
//place code here to run as soon as the movie starts to load
};
//add your listener object to you loader object
myloaderObj.addListener(myListener);
//load your movie!
myloaderObj.load(myholderclip, "external.swf");
//if you wish to display a preload for the root you can use
// the observe function instead of the load function
myloaderObj.observe(_root);
The beautiful part about using this class is it will create a behind the scenes cue for your movieclips to be loaded. You can call myloaderObj.load anywhere in your movie/movies and the class will load them one after the other…check the documentation for more cool commands…
Well a few tutorials later and a few mods to the code, i managed to get the ball rolling! First off thanks a million Naderslim for introducing movieClipLoader class, you totally saved the weekend.
It pretty much covers all the angles i’m looking for right now.
and here’s the simple stripped down bit of wondercode, (slightly modified… i added the if statement to change frame when clip is loaded):
stop();
var myMCL = new MovieClipLoader();
myMCL.onLoadProgress = function (targetMC, loadedBytes, totalBytes) {
var loadProgress = myMCL.getProgress(targetMC);
if (loadProgress.bytesLoaded == loadProgress.bytesTotal) {
_root.nextFrame();
}
}
myMCL.loadClip(“clip1.swf”,"_root.myMC1");
Done and dusted. Time to move onto other stuff. I’m sure I’ll be back asking stuff soon again, but thanks to all for the help.