5 Replies Latest reply on Aug 20, 2010 7:21 AM by injpix

    Silly Question About Loading TXT

    Whitetimer Level 1

      Hi All

       

      Been away from Flex for a while and just come back to Flex 4, but i am having trouble loading a text file.  This is what i have .....

       

      <?xml version="1.0" encoding="utf-8"?>

      <s:NavigatorContent xmlns:fx="http://ns.adobe.com/mxml/2009"

                               xmlns:s="library://ns.adobe.com/flex/spark"

                               xmlns:mx="library://ns.adobe.com/flex/mx"

                               xmlns:components="components.*"

                               width="100%" initialize="loadTXT(event)">

           <fx:Declarations>

                <!-- Place non-visual elements (e.g., services, value objects) here -->

           </fx:Declarations>

           

           <fx:Script>

                <![CDATA[

                     

                     

                     

                     private function loadTXT(event:Event):void

                     {

                          var loader:URLLoader = new URLLoader();

                          loader.load(new URLRequest("Text/sample.txt"));

                          loader.addEventListener(Event.COMPLETE, onComplete);

                     }

                     

                     private function onComplete(event:Event):void

                     {

                          var myData:String = new String(event.target.data)

                          textTXT.text=myData;

                     }

                     

                     

                ]]>

           </fx:Script>

           

           <s:layout>

                <s:VerticalLayout horizontalAlign="center" verticalAlign="top" />

           </s:layout>

           

           <s:HGroup width="100%" height="100%">

                

                <s:Panel width="300" height="100%" title="Information" dropShadowVisible="false">

                     

                </s:Panel>

                

                <s:BorderContainer width="100%" height="100%">

                     

                     <s:Label id="textTXT"/>

                     

                     <mx:ViewStack id="infoVS" width="100%" height="100%">

                          

                     </mx:ViewStack>

                     

                </s:BorderContainer>

                

           </s:HGroup>

           

      </s:NavigatorContent>

       

      Any suggestions ... I tried it using a button click and it works, but i cant get it to work when the page loads ...

       

      Many Thanks

       

      Whitetimer