Exit
  • Global community
    • Language:
      • Deutsch
      • English
      • Español
      • Français
      • Português
  • 日本語コミュニティ
  • 한국 커뮤니티
0

Preloader for loadMovie in AS2?

New Here ,
Jun 01, 2011 Jun 01, 2011

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?

TOPICS
ActionScript
2.5K
Translate
Report
Community guidelines
Be kind and respectful, give credit to the original source of content, and search for duplicates before posting. Learn more
community guidelines

correct answers 1 Correct answer

Community Expert , Jun 05, 2011 Jun 05, 2011

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(prelo

...
Translate
Community Expert ,
Jun 01, 2011 Jun 01, 2011

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

Translate
Report
Community guidelines
Be kind and respectful, give credit to the original source of content, and search for duplicates before posting. Learn more
community guidelines
New Here ,
Jun 01, 2011 Jun 01, 2011

Yep, it's a true button

Translate
Report
Community guidelines
Be kind and respectful, give credit to the original source of content, and search for duplicates before posting. Learn more
community guidelines
Community Expert ,
Jun 01, 2011 Jun 01, 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
}
}
Translate
Report
Community guidelines
Be kind and respectful, give credit to the original source of content, and search for duplicates before posting. Learn more
community guidelines
LEGEND ,
Jun 01, 2011 Jun 01, 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.

Translate
Report
Community guidelines
Be kind and respectful, give credit to the original source of content, and search for duplicates before posting. Learn more
community guidelines
New Here ,
Jun 04, 2011 Jun 04, 2011

I realise this will be terrible feedback, but it didn't work

Here's what I put in the button:

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

And here's what I put in the containing frame:

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

So I have no idea what went wrong really.

Translate
Report
Community guidelines
Be kind and respectful, give credit to the original source of content, and search for duplicates before posting. Learn more
community guidelines
Community Expert ,
Jun 04, 2011 Jun 04, 2011

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.

Translate
Report
Community guidelines
Be kind and respectful, give credit to the original source of content, and search for duplicates before posting. Learn more
community guidelines
New Here ,
Jun 05, 2011 Jun 05, 2011

Output from that:

preloadF _level0
btn _level0.instance3

Translate
Report
Community guidelines
Be kind and respectful, give credit to the original source of content, and search for duplicates before posting. Learn more
community guidelines
Community Expert ,
Jun 05, 2011 Jun 05, 2011

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);
    }
}

Translate
Report
Community guidelines
Be kind and respectful, give credit to the original source of content, and search for duplicates before posting. Learn more
community guidelines
New Here ,
Jun 05, 2011 Jun 05, 2011

ah, thankyou. That seems to work just fine

I assumed because even though my button is inside a movie clip, as it is button, it was still considered a true button.

Now there is another problem, I know its not part of the preloader business, but its still relevant:

The swf I load in with loadMovie appears before it's completely loaded. How do i stop this?

Translate
Report
Community guidelines
Be kind and respectful, give credit to the original source of content, and search for duplicates before posting. Learn more
community guidelines
Community Expert ,
Jun 05, 2011 Jun 05, 2011

assign the _alpha of your target movieclip to 0 until loading is complete.  then direct its timeline to frame 1 and assign its _alpha to 100.

Translate
Report
Community guidelines
Be kind and respectful, give credit to the original source of content, and search for duplicates before posting. Learn more
community guidelines
New Here ,
Jun 05, 2011 Jun 05, 2011

ah thanks. I was trying _visible and it wouldn't quite work for me.

Anyway. All done.

cheers

Translate
Report
Community guidelines
Be kind and respectful, give credit to the original source of content, and search for duplicates before posting. Learn more
community guidelines
Community Expert ,
Jun 05, 2011 Jun 05, 2011
LATEST

you're welcome.

Translate
Report
Community guidelines
Be kind and respectful, give credit to the original source of content, and search for duplicates before posting. Learn more
community guidelines