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

Preloader causes my SWF to run dog slow

New Here ,
Jun 25, 2010 Jun 25, 2010

Ok, I am obviously doing something seriously wrong, and admittedly I am very new to AS3 and the way CS5 has the default preloader is a bit confusing to me as well.


I have two files -- one with the preloader AS3:

var l:Loader = new Loader();
l.contentLoaderInfo.addEventListener(ProgressEvent.PROGRESS, loop);
l.contentLoaderInfo.addEventListener(Event.COMPLETE, done);
l.load(new URLRequest("part2.swf"));

function loop(e:ProgressEvent):void
{
  var perc:Number = e.bytesLoaded / e.bytesTotal;
  percent.text = Math.ceil(perc*100).toString()+"%";
}

function done(e:Event):void
{
  removeChild(percent); // was removeChildAt(0) but it make more sense this way
  percent = null;
  addChild(l);
}

Then I have another SWF with my main content called "part2.swf".

When I "publish" part2.fla, I go to ActionScript settings and select Preloader method as Preloader SWF and then on the line below I select the name of the file that points to the one above that contains the script.

Even when I do a simulate download test on the movie it compiles like a dog.  I don't understand.  If I use the "default preloader" in CS5 ... those annoying little dots with no progress bar or display text (who designed that?) ... it seems to run just fine.

I've tried putting a frame preloader in frame as I understand the "preferred" method is to call an external loader file.  So I'd really like to get an external preloader to work.

Any tips on what I'm doing wrong?  Or anyone have a simple preloader I can use in its place?

Deep bow of thanks for thinking about this with me.

TOPICS
ActionScript
1.7K
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 25, 2010 Jun 25, 2010

that preloader method is for runtime shared libraries and doesn't apply to your situation.

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 25, 2010 Jun 25, 2010

Can you point me to a good simple preloader?

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 25, 2010 Jun 25, 2010

do you want a stand-alone preloader that will load your main swf or do you want to add code to your current main swf?

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 25, 2010 Jun 25, 2010

I've failed miserably at both I'm afraid.  I've tried frame based ones like

stop();

addEventListener(Event.ENTER_FRAME, preloader);

function preloader(evet:Event){   
    var load_value:Number = this.loaderInfo.bytesLoaded / this.loaderInfo.bytesTotal;
    loader.scaleX = load_value;
    if (this.loaderInfo.bytesLoaded == this.loaderInfo.bytesTotal){
        this.gotoAndStop(2);
        removeEventListener(Event.ENTER_FRAME, preloader);
    }
}

And the external file that gets called.  My SWF is going to end up being huge -- maybe a 10+ minute interactive meditation.  From what I've read it's better to call from a separate file.  But I'm not wedded to either approach.  I can easily insert a new scene at the start, or if need be insert a new blank frame.

I'm just looking for something a bit more descriptive than the flashing dots that get bundled as a preloader in CS5 by default.

Thanks so much.

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 25, 2010 Jun 25, 2010

for a standalone preloader that's loading main.swf, use:


var ldr:Loader =  new Loader();
ldr.contentLoaderInfo.addEventListener(ProgressEvent.PROGRESS,  loop);
ldr.load(new  URLRequest("main.swf"));

function loop(e:ProgressEvent):void

{
   var f:Number = e.bytesLoaded / e.bytesTotal;
  percent.text =  Math.round(f*100).toString()+"% Loaded";  // a textfield named percent should be on stage.

if(f==1){

removeChild(percent);

addChild(ldr);

}
}

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 25, 2010 Jun 25, 2010

Thank you so much for the new code.

I must be doing something wrong in the compiling.  It still runs more than twice as slow as the same file published with the "default" adobe preloader.

I have the file preloader.swf with the following amended code in frame 1


var ldr:Loader =  new Loader();
ldr.contentLoaderInfo.addEventListener(ProgressEvent.PROGRESS,  loop);
ldr.load(new  URLRequest("part2.swf"));


var ldr:Loader =  new Loader();
ldr.contentLoaderInfo.addEventListener(ProgressEvent.PROGRESS,  loop);
ldr.load(new  URLRequest("part2.swf"));

function loop(e:ProgressEvent):void
{
   var f:Number = e.bytesLoaded / e.bytesTotal;
  percent.text =  Math.round(f*100).toString()+"%";  // a textfield named percent should be on stage.
if(f==1){
removeChild(percent);
addChild(ldr);

}
}

main content in the file part2.swf.

screenshot.jpg

I publish the part2.fla file by changing the Preloader SWF to point to the new preloader.swf file that I created with that code.  (The sample screen shot above is the adobe default preloader.)

The file with the preloader as described above is live at

http://inthelila.com/part2.html

The file with the default adobe preloader is :

http://inthelila.com/adobe-default.html

I've tried firefox, ie, emptied my cache etc.  It seems consistent.  There is something wrong with my preloader version of the file.  I have a breath exercise a few screens in where I've timed a FIVE second inhale and exhale ... with my preloader file I'd be having folks pass out because the SWF is running WAY TOO SLOW.

I know I'm missing something.  If I wasn't using armature later in the file, I'd go back and run it all through CS3.  Heck if I wasn't so stubborn I'd go back to AS2 where I was decidedly more comfortable and had preloader components that worked flawlessly.

So frustrating.

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 25, 2010 Jun 25, 2010

create a new fla.  don't change the default publish settings.  remove the duplicate code.


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 26, 2010 Jun 26, 2010

Oh my.  I thought you changed the main file content to point to the preloader file and then called the main file in your HTML.  I can see now that the URL call from within your preloader file would then be doing some kind of evil recursive call back upon itself resulting in the very slow main movie.

I added

    this.body.visible = false;
    this.text_mc.visible = false;

to remove my two objects (in addition to the percent field) and then call the file from the preloader.html and it works fine.

Clearly I'm in over my head.  But I am enjoying the surf.

Deep bow of thanks for steering me back on course.

http://inthelila.com/preloader.html

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 26, 2010 Jun 26, 2010
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