0 Replies Latest reply on Dec 20, 2006 2:07 PM by tlevieux

    Loader

    tlevieux
      The loader below never fires the init and complete events.
      Progress events are ok and the flash output console shows the expected '[SWF]... ' message too.

      package {

      import flash.display.Loader;
      import flash.display.Sprite;
      import flash.display.StageAlign;
      import flash.display.StageScaleMode;
      import flash.events.ErrorEvent;
      import flash.events.Event;
      import flash.events.HTTPStatusEvent;
      import flash.events.IOErrorEvent;
      import flash.events.ProgressEvent;
      import flash.events.SecurityErrorEvent;
      import flash.net.URLRequest;
      import flash.system.ApplicationDomain;
      import flash.system.LoaderContext;

      public class LoaderTest extends Sprite {

      private function loader_progressHandler(event:ProgressEvent) : void {
      trace("progressHandler");
      }

      private function loader_initEventHandler(event:Event) : void {
      trace("initEventHandler");
      }

      private function loader_completeEventHandler(event:Event) : void {
      trace("completeEventHandler");
      }

      private function loader_errorEventHandler(event:ErrorEvent) : void {
      trace("errorEventHandler:" + event.text);
      }

      private function loadSWF() : void {
      var loader:Loader = new Loader();

      loader.contentLoaderInfo.addEventListener(ProgressEvent.PROGRESS, loader_progressHandler);
      loader.contentLoaderInfo.addEventListener(Event.INIT, loader_initEventHandler);
      loader.contentLoaderInfo.addEventListener(Event.COMPLETE, loader_completeEventHandler);
      loader.contentLoaderInfo.addEventListener(IOErrorEvent.IO_ERROR, loader_errorEventHandler);

      var urlRequest:URLRequest = new URLRequest("some.swf");
      var loaderContext:LoaderContext = new LoaderContext();
      loaderContext.applicationDomain = ApplicationDomain.currentDomain;
      loader.load(urlRequest, loaderContext);
      }

      private function init(event:Event) : void {
      loadSWF();
      }

      public function LoaderTest() {
      stage.scaleMode = StageScaleMode.NO_SCALE;
      stage.align = StageAlign.TOP_LEFT;

      root.loaderInfo.addEventListener(Event.INIT, init);
      }
      }

      }


      So It does not work unless I add an ENTER_FRAME event listener :

      private function init(event:Event) : void {
      addEventListener(Event.ENTER_FRAME, function(event:Event) : void {
      trace("ENTER_FRAME");
      });
      loadSWF();
      }

      Really strange !
      It works fine if I use a timer too:

      private function init(event:Event) : void {
      var timer:Timer = new Timer(100);
      timer.addEventListener(TimerEvent.TIMER, function(event:Event) : void {
      trace("timer event");
      });
      timer.start();
      loadSWF();
      }


      Does someone understand something ?!

      Regards,
      Thierry