Skip to main content
Known Participant
June 1, 2011
Answered

Preloader for loadMovie in AS2?

  • June 1, 2011
  • 2 replies
  • 2592 views

First things first, please don't recommend I change to AS3 for this. It's far too late for that and not my project to be dictating.

So I'm loading some external swfs in with the loadMovie command, in the normal manner with a button:

on (release) {
    loadMovie("swfs/example-1.swf", _root.container);
}

But what I need, is to wedge a preloader in there somehow. As the swfs are around 1mb each.

I'm already using the following as a preloader for the main file, so an adaptation of it would be very welcome so I can co-ordinate the graphics:

var amountLoaded:Number = _root.getBytesLoaded() / _root.getBytesTotal();
preloaderText.text = Math.round(amountLoaded * 100) + "%";

---

if (_root.getBytesLoaded() == _root.getBytesTotal())
{ gotoAndPlay(3); }
else
{ gotoAndPlay(1); }

So would there be a way to wedge my preloader into that first lot of code?

This topic has been closed for replies.
Correct answer kglad

copy and paste the output panel result:


on (release) {

trace("btn "+this);
    preloadI=setInterval(preloadF,100,_root.container)
    loadMovie("swfs/example-1.swf", _root.container);
}

trace("preloadF "+this);

function preloadF(container:MovieClip)
{
    var amountLoaded:Number = container.getBytesLoaded() / container.getBytesTotal();
    preloaderText.text = Math.round(amountLoaded * 100) + "%";

trace(preloaderText+" "+amountLoaded);
    if (container.getBytesLoaded() == container.getBytesTotal() & container.getBytesTotal() > 0)
    {
        clearInterval(preloadI);
    }
}

So I have no idea what went wrong really.


you're using a movieclip button, not a true button.  use:



on (release) {


    _parent.preloadI=setInterval(_parent.preloadF,100,_root.container)
    loadMovie("swfs/example-1.swf", _root.container);
}


function preloadF(container:MovieClip)
{
    var amountLoaded:Number = container.getBytesLoaded() / container.getBytesTotal();
    preloaderText.text = Math.round(amountL*100)+"%";
    if (container.getBytesLoaded() == container.getBytesTotal() & container.getBytesTotal() > 0)
    {
        clearInterval(preloadI);
    }
}

2 replies

kglad
Community Expert
Community Expert
June 1, 2011

on (release) {
preloadI=setInterval(preloadF,100,_root.container)     loadMovie("swfs/example-1.swf", _root.container);
}

// attached to the frame that contains your button

funtion preloadF(mc:MovieClip){
var amountLoaded:Number = mc.getBytesLoaded() / mc.getBytesTotal();
preloaderText.text = Math.round(amountLoaded * 100) + "%";

if (mc.getBytesLoaded() == mc.getBytesTotal() & mc.getBytesTotal()>0){
clearInterval(preloadI);
// do whatever
}
}
Inspiring
June 1, 2011

Unless you are publishing to a very low target player, you might want to look at using the MovieClipLoader class instead of loadMovie and an old-school preloader.

The MCL class gives you some nice events such as onLoadError that you won't get with the hand-made approach.

kglad
Community Expert
Community Expert
June 1, 2011

is that a true button or a movieclip button?  (and, you really shouldn't attach code to objects).

Known Participant
June 1, 2011

Yep, it's a true button