Detect when loaded movie into target is fully loaded

hey all,

I am trying to load an external swf into a target. when the swf is completely loaded, i want to execute the next set of actions.

Now here is the bit i’m stuck. I am trying to develop my flash websites so that no coding is done within the child swfs.

so i would assume some code like this would work:

_root.holder.loadMovie (“child.swf”);
if(_root.holder.getBytesLoaded ==_root.holder.getBytesTotal){
_execute some other command;
}

However it doesn’t work!!!

So is there a way to detect when a specific child swf has fully loaded into a target (not _framesLoaded please!) and then set a variable to allow some other actionscript to kick in?

please help if you know,

using mx btw

cheers,

Kd

You have to test onEnterFrame. That piece of code has been given many times, just search a bit.

pom :phil:

dear Pom,

Thanks for getting back to me so quickly!

I have searched for days for this (on kirupa, flashkit etc).
I am not one of these people who post requests out of laziness!

But you said check the onEnterFrame. I don’t understand!

i can’t really get my head around syntax like:

this.onEnterFrame

Is this what you mean?

Please help if you can, i will re-pay the favour (if i can that is, i doubt there’s much about flash that i know and you don’t)!!

If you can just give me something a bit more detailed to search for, i would be grateful.

thanks mate,

kd

Something like that:

// you load the swf inside "holder"
_root.holder.loadMovie ("child.swf");
// you control the loading with the _root (or any other clip except holder)
_root.onEnterFrame = function(){
  var l = _root.holder.getBytesLoaded();
  vat t = _root.holder.getBytesTotal();
  if(l > 5 && l >= t){
    //_execute some other command;
    delete this.onEnterFrame;
  }
  else {
    // do something else while the movie's preloading
  }
}[/As]I accept cash, checks and credit cards above $100 :phil:

hehe,

Thanks for that. I’m gonna play with it and try and get my head around it.

as for the money, i can supply wisdom instead (not worth much i know - but i’m broke)!

cheers pom,

kd

sorry to bother you pom,

But the code you posted is not working.

i amended your code to:

_root.box._visible = false;
// you load the swf inside “holder”

_root.holder.loadMovie(“pana1.swf”);

// you control the loading with the _root (or any other clip except holder)
_root.onEnterFrame = function() {

var Loaded = _root.holder.getBytesLoaded();
var Total = _root.holder.getBytesTotal();
var Percent = (Loaded/Total)*100;

if (Loaded == Total) {
	//_execute some other command;
	delete this.onEnterFrame;
	_root.box._visible = true;
	
} else {
	// do something else while the movie's preloading
	_root.bar._xscale = Percent;
	_root.words = Percent;
}

};

So it’s your code, except i added a Percent var to allow my bar to’s xscale to grow and a text box named words to show the number. So i wanted an mc named box to become visible when the loading is complete, and the progress bar while loading.

what’s the problem? The child swf loads but i can’t capture the bytes loaded or total.

The only way i have found to do this so far is to mess with the prototype preloader on “best of kirupa”.

What you gave me is just a stripped down version of that right?

Please help me figure this out, and i’ll stop asking questions about preloading (which to be honest is not my main interest regarding flash).

sorry for this.

Kd

I haven’t checked that prototype, but yes, it shouldn’t be that different. But if you managed to make it work, what’s the problem? :slight_smile:

uhmm,

The problem is that i don’t really know what i’m doing!

I got it to work in principal, but i don’t really know how to customise the code and develop my own variations.

I’ll keep playing with it and see if i can suss this out, although i’m starting to lose my hair now!

thanks for your help anyways,

Kd

Just to be sure, you’re trying this online, right?

yeah of course!

I’ve done quite a few flash sites before, but i always put preloader code on the child swfs and then used them to set variables once loaded on the main stage.

But i really like the idea of developing “intelligent” main swfs, so all code is centralised and you can make change to the child swfs on the fly without messing around with lots of bits of code spread all over the place!

but this whole onEnterFrame thing, is this all part of flash mx’s oop? You know where is best to learn more? how did u learn on this subject?

thanks pom

kd

hey pom,

i’ve spent all night trying to get the code you gave me to work.

Please, please tell me why it doesn’t!!!

i’ve tried other variations of the script from other threads, and every time the same thing. The loading bar doesn’t do anything,
when the condition is met (i.e. loaded == total) any code i write after this does not execute - basically the movie is loaded and nothing else is working!

Come on, if you know the answer share it.

this is the scenario:

i have some buttons (or mc’s - don’t mind) at the top of the stage

i have a mask which is a box

in the topleft of the mask in a layer below which is masked, i have a holder mc (named holder).

when i click a button, i want the mask to tween to _yscale = 0; (registration is centre of mask).

I then want the relevant child.swf to load into holder (which of course you can’t see as the mask is _yscale =0).

when the relevant child.swf has completely loaded, i want the mask to tween to _yscale =100; therefore revealing the child.swf

then if a user clicks another button, the mask tweens back to _yscale = 0; when it reaches 0, a new child.swf is loaded and the mask tweens back to 100.

Now this can’t be soo hard?

Please help me if you can, my project deadline is fast approaching and i really don’t want to revert to doing things in my old, clumsy way.

Thanks so much for your help,

Kd

I won’t be able to use Flash for a few days, sorry :frowning: I hope (I’m sure) someone else will help you :slight_smile:

well,

thanks for your help up to now. I hope someone else reads this thread. otherwise i’m gonna have many sleepness nights.

cheers,

kd

Check this thread to see if it is of any help.
[http]
http://www.kirupaforum.com/forums/showthread.php?threadid=10357&goto=newpost
[/http]