1 Reply Latest reply on Jan 19, 2011 2:48 PM by Joe ... Ward

    Loader Class

    Kapil Waghe

      Hello All,


      I am having an problem with Loader Class,


      Here is the Scenario of my programm,



      1) Test.mxml



      <?xml version="1.0" encoding="utf-8"?>
      <!--  -->
      <mx:WindowedApplication name="HTML_complete_test"
                              initialize="init();" xmlns:s="library://ns.adobe.com/flex/spark">
          <s:Button id="btn" click="btn_clickHandler(event)" />
                  import mx.controls.Alert;
                  import flash.events.IEventDispatcher;
                  import myClasses.*;
                  private var objEx1:Ex1;


                  protected function btn_clickHandler(event:MouseEvent):void
                      objEx1 = new Ex1();




      2) Example Class - Ex1.as


      package myClasses
          import flash.events.Event;
          import flash.events.HTTPStatusEvent;
          import flash.events.IEventDispatcher;
          import flash.events.ProgressEvent;
          import flash.events.TimerEvent;
          import flash.net.URLLoader;
          import flash.net.URLRequest;
          import flash.utils.Timer;
          import mx.controls.Alert;
          import org.osmf.utils.HTTPLoadedContext;


          public class Ex1
              public var have2Wait:Boolean;
              public function Ex1()


              public function configureListeners(dispatcher:IEventDispatcher):void {
                  dispatcher.addEventListener(Event.COMPLETE, completeHandler);

              public function GetFirst():void
                  var loader:URLLoader = new URLLoader();           
                  var request:URLRequest = new URLRequest("http://www.gmail.com");
                  try {                               
                  }catch (error:Error)
                      //Alert.show("Unable to perform search, please try again.","Sorry");
              /*//Progress Listner
              public function progressListener (e:ProgressEvent):void{
                  trace("Downloaded " + e.bytesLoaded + " out of " + e.bytesTotal + " bytes");
              public function completeHandler(event:Event):void {
                      var loader:URLLoader = URLLoader(event.target);
                      have2Wait = false;
                      Alert.show("CompleteHandler: " + loader.data);
                      Alert.show("Error: " + error.message);







      One thing I want to share is that whole code is working fine....


      When I click on button and code execution executes the   loader.load(request);  it will take some to executes the completeHandler function.


      If we run it with debug option the the execution gets completed and then the completeHandler start execution.


      If I place some code over MXML (from where we call the funcion) it also executed it.


      I want to STOP on class untill the completeHandler gets completed.



      Hope you understand my problem and will solve it.



        • 1. Re: Loader Class
          Joe ... Ward Level 4

          I'm not 100% sure my understanding of your problem is correct, but if you want to wait for objEx1 to complete some operation in the main MXML class, you could have Ex1 extend EventDispatcher and then dispatch your own complete event at the end of Ex1.completeHandler.