A Flash Developer Resource Site

Results 1 to 7 of 7

Thread: scolling text which was loaded as a variable?

  1. #1
    Sick of the web
    Join Date
    Nov 2000
    Posts
    160

    scolling text which was loaded as a variable?

    I have loaded a .txt file into a dynamic text box in my movie.... however the scroll component will not work... It only seems to work when I simply paste the text into the text box.....

    Can you scroll text which has been loaded into the text box?


    thanks,

  2. #2
    Senior Member
    Join Date
    Mar 2001
    Posts
    141
    gold,

    make sure your variable names agree, and that the scrollbar is looking for the right text field. I know this isn't a whole lot of help, but I noticed that no one had so much as replied, so I wanted to throw you a bone...
    Flash is Life...The rest is just tweens.
    .::T::.

  3. #3
    Sick of the web
    Join Date
    Nov 2000
    Posts
    160
    Yes, everything is a-ok and yet no scrolling occures when I load the text in via loadVariablenum. When the text is simply placed into the dynamic text field the scrolling works fine. But not when the text is loaded into the text field.

    Question to all: can text loaded into a text field be scrolled using the flash scroll component?

    thanks

  4. #4
    Member
    Join Date
    Feb 2002
    Posts
    79
    Hi goldpan,

    I have the same problem (fill the text field with dynamic text by press a button).
    Do you have solved the problem, our do you know a workaround??

    David

  5. #5
    Junior Member
    Join Date
    Jul 2003
    Location
    Colorado Springs
    Posts
    3

    me too

    I'm trying to overcome the same difficulty. I was just about to leap for joy when I saw this thread, thinking my two week trial had ended. God grant me patience....

    John

  6. #6
    Sick of the web
    Join Date
    Nov 2000
    Posts
    160
    John 75

    Man ,, you came accrossed an old thread....

    Anyway,,,, I found the answer and here it is....

    Note: Before reading this TechNote you should be comfortable with creating dynamic text fields in Macromedia Flash MX, using the ScrollBar component and working in Expert mode in the Actions panel. Begin by reading Create scrolling text in Flash MX (TechNote 16142).

    Loading external text to a dynamic text field

    An example of external text using the ScrollBar component.
    Requires Macromedia Flash Player 6 to view.

    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" then 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. In Flash MX text is it's own 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, for details). 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 in Create scrolling text in Flash MX (TechNote 16142).

    Note: Do NOT give the text field a variable name. But do give it an instance name. In this example the instance name is 'scroller' and line type popup is set 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.
    //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 then 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 isn't absolutely necessary to assign the text to the Text field instance at this time. This could be done in a later frame. But it's 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");
    }
    }



    http://www.macromedia.com/support/fl...ng_text_mx.zip

  7. #7
    Junior Member
    Join Date
    Jul 2003
    Location
    Colorado Springs
    Posts
    3
    Thanks for writing back. I missed the date on the original post.

    I found this example, and was able to successfully use it. But this example loads the text as soon as you start the movie. I want to load the text, (the variable) when I click the button.

    In order to use the scroll bar, don't you have to use the new LoadVars() thing, rather than the loadvariables?

    I have a lot of articles, some 10 or more paragraphs, that I want to load into the same field whenever I click a different button.

    This is really my first hangup in Actionscript. My site is coming together reasonably well, I just can't seem to get past this one.

    Thanks again!

    John

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