1 Reply Latest reply on Sep 2, 2009 4:29 AM by Cédric LG

    Loading Text Problem

    Whitetimer Level 1

      Hi ...

       

      I have a custom component which has 4 linkButtons on the top.  I have 1 textArear component and 4 seperate text files.  What would be the best way to load each file from one of the linkButtons into the textArea ?

       

      Any suggestion please ?

       

      Many Thanks

       

      OH ... I did try this but did not seem quite right

       

                  // IMPORTS //
                  import flash.events.MouseEvent;
                  import flash.events.Event;
                  // VARIABLES //
                  private var loader:URLLoader = new URLLoader();
                  private var request:URLRequest = new URLRequest('Assets/Text/WhitetimeLevelOneClass.txt');
                  // METHODS //
                  private function loadText(event:Event):void
                  {
                      loader.load(request);
                      loader.addEventListener(Event.COMPLETE, onComplete);
                  }
                  
                  private function selectText(event:Event):void
                  {
                       if(event.target == wtL1LB){request.url = 'Assets/Text/WhitetimeLevelOneClass.txt';}
                       if(event.target == wtL2LB){request.url = 'Assets/Text/WhitetimeLevelTwoClass.txt';}
                       if(event.target == wtL3LB){request.url = 'Assets/Text/WhitetimeLevelThreeClass.txt';}
                       if(event.target == wtL4LB){request.url = 'Assets/Text/WhitetimeLevelFourClass.txt';}
                  }
                  
                  private function onComplete(event:Event):void
                  {
                      wtcTA.htmlText = event.currentTarget.data;
                  }
      
        • 1. Re: Loading Text Problem
          Cédric LG

          Hi,

          There are two main ways to load extenal data.

          1. On runtime by calling an AMF service or using a component like URLRequest.
          2. On compilation by using an Embed attribute. The example below shows you how to embed the content of a HTML file

           

          [Bindable]
          [Embed(source="assets/text.html", mimeType="application/octet-stream")]
          private var MyTextClass:Class;
          private var daTxt:ByteArrayAsset = ByteArrayAsset(new MyTextClass());
          [Bindable]  
          private var daTxtStr:String = daTxt.toString();

           

          Warning, if you are loading your content on runtime, the files have to be availables to all clients that are running your app (1). Indeed, the content is not included in the swf file by the compiler.