2 Replies Latest reply on Feb 11, 2011 6:41 AM by dharmes

    loading external file

    dharmes Level 1

      i have created plain text field and managed to load it from external file using the AS3 code below. Now i want to load multiple text field but this time in a button, how can i do that?

       

      this is my button code: proposal_btn

                                        story_btn 

       

       

      var textLoader:URLLoader = new URLLoader();

      textLoader.addEventListener(Event.COMPLETE, textLoaded);

      textLoader.load(new URLRequest("assets/welcome.txt"));

       

      var dragRect:Rectangle = new Rectangle(drag.x,drag.y,0,bar.height - drag.height);

      drag.addEventListener(MouseEvent.MOUSE_DOWN, dragMouseDown);

       

      function textLoaded(evt:Event):void

      {

       

      info_txt.text = textLoader.data;

      }

       

      function dragMouseDown(evt:MouseEvent):void

      {

      drag.startDrag(false,dragRect);

      stage.addEventListener(MouseEvent.MOUSE_UP, dragMouseUp);

      addEventListener(Event.ENTER_FRAME, scrollText);

      }

       

      function dragMouseUp(evt:MouseEvent):void

      {

      drag.stopDrag();

      stage.removeEventListener(MouseEvent.MOUSE_UP, dragMouseUp);

      removeEventListener(Event.ENTER_FRAME, scrollText);

      }

       

      function scrollText(evt:Event):void

      {

      var percentScrolled:Number = (drag.y - bar.y)/(bar.height - drag.height);

      info_txt.scrollV = Math.round(percentScrolled * info_txt.maxScrollV);

      }

        • 1. Re: loading external file
          Ned Murphy Adobe Community Professional & MVP

          I am not really sure of the question, but here's an example using your info_txt code such that clicking the story_btn will load it... you should be able to use this as an example for others...

           

          var textLoader:URLLoader;

            

          function loadStory(evt:MouseEvent):void {

               textLoader = new URLLoader();

               textLoader.addEventListener(Event.COMPLETE, textLoaded);

               textLoader.load(new URLRequest("assets/welcome.txt"));

          }

           

          story_btn.addEventListener(MouseEvent.CLICK, loadStory);

           

          function textLoaded(evt:Event):void {

               info_txt.text = textLoader.data;

          }

          • 2. Re: loading external file
            dharmes Level 1

            excellent. Now if i want to load another text field on proposal_btn, can i do this:

             

            var textLoader:URLLoader;

             

            function loadStory(evt:MouseEvent):void {

                 textLoader = new URLLoader();

                 textLoader.addEventListener(Event.COMPLETE, textLoaded);

                 textLoader.load(new URLRequest("assets/welcome.txt"));

                 textLoader.load(new URLRequest("assets/welcome1.txt"));

            }

             

            story_btn.addEventListener(MouseEvent.CLICK, loadStory);

             

            function textLoaded(evt:Event):void {

                 info_txt.text = textLoader.data;

            }

             

            proposal_btn.addEventListener(MouseEvent.CLICK, loadStory);

             

            function textLoaded(evt:Event):void {

                 info_txt.text = textLoader.data;

            }