2 Replies Latest reply on Jan 3, 2009 4:54 PM by fireworld2406

    Overriding HTMLLoader.Load() method

    fireworld2406
      Hello----
      I am trying to override the HTMLLoader Load method to check the content type. If the content type is not text/html or text/plain, then a download window is supposed to open. All of this is working, except the web page is not being displayed in the <mx:HTML> control now. Here is the overridden code and supporting functions:

      public class Html_download extends HTMLLoader
      {
      public override function load(urlRequestToLoad:URLRequest):void {
      trace("custom load");
      var urlload:URLStream=new URLStream();
      urlload.addEventListener(HTTPStatusEvent.HTTP_RESPONSE_STATUS,typechecker);
      //urlload.addEventListener(Event.COMPLETE,loaddone);
      urlload.load(urlRequestToLoad);
      }

      public function typechecker(event:HTTPStatusEvent) {
      trace("checking type");
      for (var i:int=0;i<event.responseHeaders.length;++i) {
      if (event.responseHeaders .name=="Content-Type") {
      trace("type is "+event.responseHeaders
      .value);
      trace("text/html search result: "+event.responseHeaders .value.search("text/html"));
      trace("text/plain search result: "+event.responseHeaders
      .value.search("text/plain"));
      trace("response url: "+event.responseURL);
      if ((event.responseHeaders .value.search("text/html")==-1)&&(event.responseHeaders.value.search("text/plain")==-1)) {
      var fr:FileReference=new FileReference();
      fr.download(new URLRequest(event.responseURL));
      }
      }
      }
      }

      How do I remedy the situation?

      Thank you in advance for your hellp.

        • 1. Overriding HTMLLoader.Load() method
          fireworld2406 Level 1
          Maybe the HTML control doesn't like overridden methods? I tried basically recreating the entire class by using "super.methodname()" for every function where it was allowed and it still doesn't work......
          • 2. Re: Overriding HTMLLoader.Load() method
            fireworld2406 Level 1
            Anyone?

            I did a little bit more investigating and found that
            a) No "complete" event is ever received (even if manually sent via this.dispatchRequest(new Event(Event.COMPLETE));)
            b) The loaded property never changes to true
            c) I am doing something wrong with how I am assigning the different class for HtmlLoader because even if I assign a regular HTMLLoader class in the same way (html1.htmlLoader=test), it still doesn't work.

            I also found a property called HtmlLoaderFactory. I have no idea how to use it though. If someone could explain how to use it, I would be most grateful.

            Thank you for your help in advance.