5 Replies Latest reply on Jan 19, 2007 6:09 AM by kimbflex

    urlloader and html

    kimbflex
      Hello,

      I'm using URLLoader to display some simple html in a text component like so:

      [Bindable]
      public var htmlImport:String;
      [Bindable]
      public var loader:URLLoader = new URLLoader();
      [Bindable]
      public var request:URLRequest = new URLRequest("page1.html");

      private function completeHandler(event:Event):void{
      loader = URLLoader(event.target);
      htmlImport = String(loader.data);
      mytextArea.htmlText = htmlImport;
      }

      public function init():void {
      loader.load(request);
      loader.addEventListener(Event.COMPLETE, completeHandler);
      }

      This works fine initially although if I want to load a different html file afterwards by doing e.g:

      request.url = 'page2.html';
      loader.load(request);

      It fails with #error 2025

      What am I doing wrong?

        • 1. Re: urlloader and html
          Level 1
          Adobe has a good page with a description of all the run-time errors:

          http://livedocs.macromedia.com/flex/2/langref/runtimeErrors.html

          Error 2025 is "The supplied DisplayObject must be a child of the caller."

          Does it give you a stack trace as well? Telling you what line (or method) the code has failed at? It might give you more insight to your problem. If you have Flex Builder 2, see if you can't step through the code to determine what line it fails at.

          Since it is complaining about a DisplayObject, I would imagine it might have something to do with the mytextArea - assuming that, mytextArea is an object that subclasses DisplayObject.

          --Andy
          • 2. Re: urlloader and html
            kimbflex Level 1
            ArgumentError: Error #2025: The supplied DisplayObject must be a child of the caller.
            at flash.text::TextField/set htmlText()
            at mx.core::UITextField/set htmlText()[C:\dev\flex_201_gmc\sdk\frameworks\mx\core\UITextField.as:319]
            at mx.controls::TextArea/mx.controls:TextArea::commitProperties()[C:\dev\flex_201_gmc\sdk\fr ameworks\mx\controls\TextArea.as:1841]
            at mx.core::UIComponent/validateProperties()[C:\dev\flex_201_gmc\sdk\frameworks\mx\core\UICo mponent.as:5300]
            at mx.managers::LayoutManager/mx.managers:LayoutManager::validateProperties()[C:\dev\flex_20 1_gmc\sdk\frameworks\mx\managers\LayoutManager.as:517]
            at mx.managers::LayoutManager/mx.managers:LayoutManager::doPhasedInstantiation()[C:\dev\flex _201_gmc\sdk\frameworks\mx\managers\LayoutManager.as:667]
            at Function/ http://adobe.com/AS3/2006/builtin::apply()
            at mx.core::UIComponent/mx.core:UIComponent::callLaterDispatcher2()[C:\dev\flex_201_gmc\sdk\ frameworks\mx\core\UIComponent.as:7909]
            at mx.core::UIComponent/mx.core:UIComponent::callLaterDispatcher()[C:\dev\flex_201_gmc\sdk\f rameworks\mx\core\UIComponent.as:7852]
            • 3. Re: urlloader and html
              Level 1
              I loaded your code into application and changed the html page names to pages that i had, however, I was able run the code without error. I'm running the 9_0_28 debug flash player, you may want to check to see which flash player you are running.

              my mini-app:

              <?xml version="1.0" encoding="utf-8"?>
              <mx:Application
              xmlns:mx=" http://www.adobe.com/2006/mxml"
              x="0" y="0"
              paddingLeft="0"
              paddingTop="0"
              paddingBottom="0"
              paddingRight="0"
              backgroundColor="#FFFFFF"
              initialize="init();" >
              <mx:Script>
              <![CDATA[

              [Bindable]
              public var htmlImport:String;
              [Bindable]
              public var loader:URLLoader = new URLLoader();
              [Bindable]
              public var request:URLRequest = new URLRequest("index.html");

              private function completeHandler(event:Event):void{
              loader = URLLoader(event.target);
              htmlImport = String(loader.data);
              happyTextArea.htmlText = htmlImport;
              }

              public function init():void {
              loader.load(request);
              loader.addEventListener(Event.COMPLETE, completeHandler);
              }

              private function makeHappyButton(event:Event):void
              {
              request.url = 'contact.html';
              loader.load(request);
              }
              ]]>
              </mx:Script>
              <mx:Panel id="happyPanel" layout="absolute" percentWidth="100" percentHeight="100" >
              <mx:VBox>
              <mx:TextArea id="happyTextArea" height="400" width="300"/>
              <mx:Button id="clickButton" label="click me" click="makeHappyButton(event)" />
              </mx:VBox>
              </mx:Panel>
              </mx:Application>

              It could be other code in your application or the html file itself, that you are loading the second time around. You could load page2 first and see if that is the problem.

              --Andy
              • 4. Re: urlloader and html
                kimbflex Level 1

                Thanks for your help. I got it sorted.

                It turned out ot be a small issue if the html contains an <img> tag with the width and height set . You can set the width or the height of the <img> but Flash throws the #2025 error if both parameters are included.

                • 5. Re: urlloader and html
                  kimbflex Level 1

                  The #2025 error/bug also happens if the textArea is resized then switched to another html source. I got around this by adding a on resize event function to the application e.g:

                  function reloadHTML() {
                  happyTextArea.htmlText = htmlImport;
                  }

                  Seems to stop the error... so far.