A Flash Developer Resource Site

Results 1 to 9 of 9

Thread: Getting scrollbars to work after importing txt file.

  1. #1
    Junior Member
    Join Date
    May 2004
    Location
    Dayton
    Posts
    6

    Getting scrollbars to work after importing txt file.

    So i am working on a timelne project in which when an obfect is clicked on the timeline, it shows more info in a text box above. The problem i am running into, becuase i want to use outside .txt files for the more info, is that when the text is loaded into the text box via loadVariables, the scrollbar component on that box will not refresh, hence there is no scroll box on the bar.
    I've looked into many ideas and keep running into walls. I'm up for anything, as long as i can edit the text in a word processor. so if anyone has some advice or help, PLEASE HELP ME!

  2. #2
    Banned
    Join Date
    Apr 2001
    Location
    Montréal, Québec.
    Posts
    25,397

  3. #3
    Junior Member
    Join Date
    Oct 2001
    Posts
    27
    I have followed the tutorial listed to the letter (not a very good tutorial it would be better if they went into more detail) and it still comes up "Undefined." and of course the scrollbar doesnt work. Any help?

    Using MX 2004. with the downloaded component for the scrollbar from Macromedia Exhange (MX component for 2004 download).

    Here is the errors I keep getting:

    **Warning** Scene=Scene 1, layer=actions, frame=1:Line 2: The identifier 'loadVars' will not resolve to built-in object 'LoadVars' at runtime.
    loadVarsText = new loadVars();

    Total ActionScript Errors: 1 Reported Errors: 1

    -->(of course I have no Idea what that means).

    Thanks in advance,


    Tutorial
    ---External text and the Flash MX ScrollBar Component

    Depending on your specific needs, it may be necessary to load text from an external file into a dynamic text field in Flash MX. The following example and steps illustrate one way to add this functionality to Flash movies.

    Loading external text to a dynamic text field

    An example of external text using the ScrollBar component.

    Download Windows source file dynamic_text_MX.zip (44K)
    Download Macintosh source file dynamic_text_MX.sit (44K)

    In Macromedia Flash 5 and earlier, data from an external text source was loaded using the loadVariables command. The dynamic text field is given a variable name, and the text file contains text that sets that variable name. For example, if the text field variable name is myText, the text file may look like this (spaces have been URL encoded):

    myText=This%20is%20a%20lengthy%20variable.

    Loading text into a dynamic text field in Flash MX is done differently. Text is an ActionScript object, so a text field can have both a variable name and an instance name (see Flash MX Text fields have instance names and variable names, TechNote 16184).

    Flash MX also introduces a more sophisticated action for loading external data called loadVars(). These two methods are combined to load external text to a scrolling text field created using the ScrollBar component.

    1 Create a scrolling dynamic text field using the techniques described above.
    Note: Do NOT give the text field a variable name, instead give it an instance name. In this example the instance name is scroller and set the line type popup menu to multiline.


    2 Create an external text file to hold the data. In this example the text file is named test.txt, and is in the same directory as the final SWF.

    The format of the text should be name=value pairs, separate by ampersands. For example, in this sample file the text file begins "var1=All dynamic..."
    3 Next add the ActionScript to load the external text file. This script uses the new loadVar() action, and is assigned as a frame script. (I would assume to do this on the first frame of the script).

    //Create a new instance of the loadVars object and assign it to a variable
    loadVarsText = new loadVars();
    4 Load external text into the loadVars object:

    loadVarsText.load("test.txt");
    5 Check for a successful load of the data. If the data is loaded, the text method of the Text object can be used to assign the data to the text field:

    //assign a function which fires when the data is loaded:
    loadVarsText.onLoad = function (success){
    if (success){
    trace ("done loading");
    //Now that we know the data is loaded,
    //set the text content of the Text Field
    //with the instance name "scroller" equal to the
    //contents of the variable
    scroller.text = this.var1;
    }else{
    trace ("not loaded");
    }
    }

    Note: It is not absolutely necessary to assign the text to the Text field instance at this time. This could be done in a later frame, but it is a good idea to create a function to insure that the data has loaded.

    In this example the data is held inside the loadVarsText object, so it can be called at any time using:

    scroller.text = loadVarsText.var1


    Using HTML formatting
    To use html formatting with dynamically loaded text use the TextField.htmlText property. This allows Flash MX to parse the HTML tags that are contained in the loaded text.

    There are two parts to this process: 1 Set the TextField.html property to true to identify the text field as having HTML formatting. Using the above example:

    scroller.html = true;
    2 Use the TextField.htmlText property instead of TextField.text to set the variable:

    scroller.htmlText=this.var1;
    The final script for dynamically loaded text with HTML formatting

    //assign a function which fires when the data is loaded:
    loadVarsText.onLoad = function (success){
    if (success){
    trace ("done loading");
    //Now that we know the data is loaded,
    //set the text content of the Text Field
    //with the instance name "scroller" equal to the
    //contents of the variable scroller.html = true;
    scroller.htmlText = this.var1;
    }else{
    trace ("not loaded");
    }
    }


    And just for completeness, here is the test.txt:

    var1=<HTML>All dynamic and input text fields in a Flash movie are instances of the TextField object. You can give a text field an instance name in the Property inspector and use the methods and properties of the TextField object to manipulate it with ActionScript. TextField instance names are displayed in the Movie Explorer and in the Insert Target Path dialog box in the Actions panel. The TextField object inherits from the Object object. To create a text field dynamically, you can use the MovieClip.createTextField method. The TextField object is supported by Flash Player 6 and later versions of the Flash Player.</HTML>
    Ray Balhorn

  4. #4
    Banned
    Join Date
    Apr 2001
    Location
    Montréal, Québec.
    Posts
    25,397
    On MX2004, if you switch to AS1 rather than AS2, the above should work!

  5. #5
    Junior Member
    Join Date
    May 2004
    Location
    Dayton
    Posts
    6
    Thanks for the help. With that tut i got my scrollbars to work.

  6. #6
    Plutarian(From Pluto, stupid!) kitchee's Avatar
    Join Date
    Aug 2001
    Posts
    438
    How did you finally figure this out. I get a load of errors when changing to AS`1 from AS2.

    What is the solution.

    I am haveing the exact same issue.


  7. #7
    Banned
    Join Date
    Apr 2001
    Location
    Montréal, Québec.
    Posts
    25,397
    Well you shouldn't get errors on the MX scrollbar component and a dynamic textfield. You could be getting errors on the rest of your scripting or if your using the MX2004 "text area" (or whatever it's now called...) component.

  8. #8
    Plutarian(From Pluto, stupid!) kitchee's Avatar
    Join Date
    Aug 2001
    Posts
    438
    Got it.

    I got sick of screwing with it a bought the one form the exchange for $6. it works great and saves me a hour or 2 time banging the keys.

    First one I ever bought.

    It's really stupid when a Macromedia tute and example does not work! LOL

    Bunch of idots over there..

  9. #9
    Member
    Join Date
    May 2003
    Posts
    34
    What if I've got an existing site with _my_ existing homemade scrollbar? Is there a way to integrate my scrollbar or must I use the Macromedia component?

    - emk

Posting Permissions

  • You may not post new threads
  • You may not post replies
  • You may not post attachments
  • You may not edit your posts
  •  




Click Here to Expand Forum to Full Width

HTML5 Development Center