Skip to main content
Inspiring
August 30, 2014
Question

Preloader repeats loading

  • August 30, 2014
  • 1 reply
  • 942 views

I have the following preloader,

package

{

  import flash.display.Loader;

  import flash.display.Sprite;

  import flash.events.Event;

  import flash.events.ProgressEvent;

  import flash.net.URLRequest;

  public class Main extends Sprite

  {

  private var l:Loader = new Loader();

  public function Main():void {

  l.contentLoaderInfo.addEventListener(ProgressEvent.PROGRESS,loop);

  l.contentLoaderInfo.addEventListener(Event.COMPLETE, done);

  trace("loading ...");

  l.load(new URLRequest("./myapp.swf"));

  }

  private function loop(e:ProgressEvent):void

  {

  trace("loaded " + e.bytesLoaded + " bytes");

  }

  private function done(e:Event):void {

  trace("done");

  addChild(l);

  }

  }

}

I expect it to load myapp.swf and display it when done. But it seems to load it again and again, as I have the following output. It goes on like that endlessly and never displays myapp.swf. What is going on?

loading ...

loaded 0 bytes

loaded 65536 bytes

...

loaded 9448859 bytes

loading ...

done

loaded 0 bytes

loaded 65536 bytes

...

loaded 9448859 bytes

loading ...

done

loaded 0 bytes

loaded 65536 bytes

...

This topic has been closed for replies.

1 reply

September 3, 2014

Can you add an IO Error event listener to your Loader and see if anything happens there?

l.contentLoaderInfo.addEventListener(IOErrorEvent.IO_ERROR, onIOError);

private function onIOError(e:IOErrorEvent):void {

trace(e.text)

}

Also, does your loaded SWF have to be explicitly initialized with an init() function (or something similar) or does it just work once it is loaded/running?

Inspiring
September 4, 2014

Thank you so much for your suggestions.

I have added eventlistener on io error as you suggested, but it didn't catch any error.

My swf had no init() function. Just to test, I renamed my main() function to init and added a main() just to call init(). The result is the same as before (keeps loading again and again).

I also created a very simple swf with the following code,

package

{

  import flash.ui.*;

  import flash.display.*;

  public class Main extends Sprite

  {

  public function Main():void

  {

  init();

  }

  private function init():void

  {

  this.graphics.lineStyle(5, 0xFF0000);

  this.graphics.drawCircle(100, 100, 100);

  }

  }

}

Loading this swf file in my preloader gives me the following message in the debug window,

loading ...

loaded 0 bytes

loaded 802 bytes

Process not responding.

Process not responding.

....

I don't know why it is different now. Both swf plays fine in flash player. I did notice, in flash player, the control is set to loop and grayed out. Any more suggestion is greatly appreciated. Thank you.

Inspiring
September 4, 2014

In face, my effort on creating a preloader originated from the need to create a splash screen for android app. Because unlike iOS app, where you can put the Default.png and Default-568h.png in your icons to create splash screen, android app doesn't take those. I read online that you can achieve this by creating a simple preloader that loads fast and package both swf files in .apk.

If there is any other way to achieve splash screen, then I would not need to use the preloader.

I also read that flesh builder or some commercial tool can add splash screen for android app, but I am using flashdevelop to build my app. Is there a solution there?