6 Replies Latest reply on Jan 2, 2009 8:45 PM by dstx

    Dynamic Text with external .txt files

    dstx Level 1
      I need help getting dynamic text to display. I've used the following tutorials (among others).
      http://www.kirupa.com/developer/mx/dynamic_scroller.htm
      http://www.kirupa.com/developer/mx/multiple_dynamictext.htm

      In Flash 8 on last frame of maintimeline of movie, I have a layer with a background image, 2 buttons and a dynamic textbox (made scrollable) with scrollbar component. Textbox is given a var of "content", and an instance name of "textBox", which is referenced in scrollbar parameters.

      I have created 3 text .txt files, and saved them to same folder with movie .swf file. Text in files is preceeded by "content=" on line preceeding text to correspond with var of dynamic textbox. The files were created in Rich text format on Mac OSX4.11 and saved with .rtf extension, then file extension was changed to .txt (wouldn't save as .txt)

      I've added the following actionscript to this last frame:

      loadText = new LoadVars();
      loadText.load("TEXTintro.txt");
      //creating the loadVarsText function
      loadText.onLoad = function(success){
      if (success){
      textBox.text = this.content;
      }
      else{
      trace("Error loading external content");
      }
      }

      Buttons have an instance name assigned with the following actionscript:
      on (release) {
      loadText = new LoadVars();
      loadText.load("TEXT1.txt");
      loadText.onLoad = function(success){
      if (success){
      textBox.text = this.content;
      }
      else{
      trace("Error loading external content");
      }
      }

      When I test movie, I can see buttons on last frame of movie, but they don't load any text when pressed, and "undefined" text appears in upper left corner of text box before I press either button.

      I am getting the following Output errors:
      **Error** Scene=MoonOfWintertime, layer=TextBox, frame=2500:Line 1: Statement block must be terminated by '}'
      on (release) {

      **Error** Scene=MoonOfWintertime, layer=TextBox, frame=2500:Line 11: Syntax error.
      }

      **Error** Scene=MoonOfWintertime, layer=TextBox, frame=2500:Line 1: Statement block must be terminated by '}'
      on (release) {

      **Error** Scene=MoonOfWintertime, layer=TextBox, frame=2500:Line 11: Syntax error.
      }

      Total ActionScript Errors: 4 Reported Errors: 4
        • 1. Dynamic Text with external .txt files
          Ned Murphy Adobe Community Professional & MVP
          I haven't taken time to review the details of the code except to see that the error messages are probably accurate... as far as I can see there are 4 "{" but only 3 "}" for your button code.

          Also, you probably need to declare the content variable (var content;) in the code outside any functions. Defining it for/on the textfield alone doesn't normally fly (for me).

          I'm not sure about the impact of using a disguised rtf file. Don't Macs come with a simple ascii text editor? With all the condemning TV ads about PC's, I'd think they'd have that covered.
          • 2. Re: Dynamic Text with external .txt files
            dstx Level 1
            What should I check or change based upon error Output?
            I don't know enough to understand what errors are indicating.

            Also, how do I "declare the content variable (var content;) in the code outside any functions" as you suggest?
            • 3. Re: Dynamic Text with external .txt files
              Ned Murphy Adobe Community Professional & MVP
              Add another "}" to the end of your buttons' code

              var content;
              loadText = new LoadVars();
              ...etc
              • 4. Re: Dynamic Text with external .txt files
                dstx Level 1
                No more output errors, buttons still not working, but I got my intro .txt file to load in textbox that loads with frame using the following code I tried from another tutorial:
                loadText = new LoadVars();
                loadText.onLoad = function() {
                textBox.html=true;
                textBox.htmlText = this.textContent;
                };
                loadText.load("TEXTintro.txt");

                Tried the following code with buttons, but doesn't work. Other code suggestions?

                on (release) {
                loadText = new LoadVars();
                loadText.onLoad = function() {
                };
                loadText.load("TEXT2.txt");
                }

                on (release) {
                loadText = new LoadVars();
                loadText.onLoad = function() {
                textBox.html=true;
                textBox.htmlText = this.textContent;
                };
                loadText.load("TEXT1.txt");
                }
                • 5. Re: Dynamic Text with external .txt files
                  dstx Level 1
                  Just got button to work using the following:

                  on (release) {
                  loadText = new LoadVars();
                  loadText.load("TEXT1.txt");
                  loadText.onLoad = function() {
                  textBox.text = this.textContent;
                  };
                  }


                  Can anyone tell me how to style text in dynamic textbox?
                  Right now, all I can get is the font type, size and color as set in the textbox properties window.

                  Is it possible to attach or embed a CSS stylesheet?
                  And use html in external txt file for more control of text display?

                  If this can be done, how do you do it?
                  • 6. Re: Dynamic Text with external .txt files
                    dstx Level 1
                    BTW the code above only works on new button I draw with toolbar and convert to button symbol.

                    How can I get code to work with button component I select from Components window?