dcsimg
A Flash Developer Resource Site

Page 1 of 2 12 LastLast
Results 1 to 20 of 23

Thread: Loading text into dynamic text boxes

  1. #1
    Wait- what now? tidenburg's Avatar
    Join Date
    Dec 2005
    Posts
    1,472

    Loading text into dynamic text boxes

    the title pretty much explains. how do i load text from a .txt file into a dynamic text box.
    "I'd only told them the truth. Was that so selfish? Our integrity sells for so little, but it is all we really have. It is the very last inch of us, but within that inch, we are free."

  2. #2
    Moderator whispers's Avatar
    Join Date
    Mar 2001
    Location
    CFA2h (respect the HEX)
    Posts
    12,755
    IMHO- the best way to do this is using a varObject. Heres an example:
    code:

    newText = new LoadVars();
    newText.onLoad = function(success) {
    if (!success) {
    someTextField_txt.htmlText = true;
    someTextField_txt.htmlText = "<b>FAILED TO LOAD</b>"
    trace("failed to load");

    } else {
    //do whatever you want to happen IF successful
    someTextField_txt.htmlText = true;
    someTextField_txt.htmlText = (newText.info); //info = variable in text file
    }
    };
    newText.load("someTextFile.txt");
    }


    this example assumes that inside the textFile you have the "data" set up as:
    &info=etc..etc.....and some text..etc..etc...more text...etc.
    explaination of how it works:

    newText = new LoadVars();
    this declares/creates a NEW loadVar Object (we called it 'newText')

    newText.onLoad = function(success) {
    we are telling FLASH what to do when the textFile is loaded..

    • if (!success) {
      someTextField_txt.htmlText = true;
      someTextField_txt.htmlText = "<b>FAILED TO LOAD</b>"
      trace("failed to load");
      }

    this section is telling FLASH what to do if text DID NOT LOAD CORRECTLY.

    • else {
      //do whatever you want to happen IF successful
      someTextField_txt.htmlText = true;
      someTextField_txt.htmlText = (newText.info); //info = variable in text file
      }

    this section is telling FLASH how to react if the textFile WAS LOADED CORRECTLY!

    newText.load("someTextFile.txt");
    and now finally we actually make the call to LOAD the textFile with our data in it.

  3. #3
    Wait- what now? tidenburg's Avatar
    Join Date
    Dec 2005
    Posts
    1,472
    k thanks ill try it
    "I'd only told them the truth. Was that so selfish? Our integrity sells for so little, but it is all we really have. It is the very last inch of us, but within that inch, we are free."

  4. #4
    Wait- what now? tidenburg's Avatar
    Join Date
    Dec 2005
    Posts
    1,472
    hmm it doesnt seem to work :S which parts should i replace? and how should i lay out my text file?
    "I'd only told them the truth. Was that so selfish? Our integrity sells for so little, but it is all we really have. It is the very last inch of us, but within that inch, we are free."

  5. #5
    Moderator whispers's Avatar
    Join Date
    Mar 2001
    Location
    CFA2h (respect the HEX)
    Posts
    12,755
    it works... what did YOU try hat makes you say it doesnt work? are you even getting the FAILED TO LOAD error message? are you naming your objects correctly?..giving them INSTANCE names?

    the inside of your textFile shold look like as posted above:
    &info=your text here....your text here...your text here.....
    make a text field on your stage with the INSTANCE NAME OF:

    someTextField_txt


    and the NAME of your textFile needs to be:

    someTextFile.txt

  6. #6
    Wait- what now? tidenburg's Avatar
    Join Date
    Dec 2005
    Posts
    1,472
    ok ive just figured out how to do it. Thanks
    one last thing though;
    how would i get it so i have in the text file:

    &tidenburg#14#phonenumber#adress#

    and load them all into seperate text boxes
    e.g.:

    NAME-------AGE-----PHONE NUMBER
    tidenburg-----14-------01245354664
    tidusen-------14-------012345678
    toby----------14-------012456778
    "I'd only told them the truth. Was that so selfish? Our integrity sells for so little, but it is all we really have. It is the very last inch of us, but within that inch, we are free."

  7. #7
    Moderator whispers's Avatar
    Join Date
    Mar 2001
    Location
    CFA2h (respect the HEX)
    Posts
    12,755
    well, your WHOLE data (VAR) object is the text file....refered to as: newText

    now in the code we have already...we see that the object newText has some "properties"...so fa it only has 1...which is INFO. which is why we call the text like newText.info
    someTextField_txt.htmlText = (newText.info); //info = variable in text file
    you should by now know that all VARS in the text file need to be seperated by the '&' sign..
    so you would need to seperate them as so: &name=joe&age=14&phone=12345678

    and then you AS would be like:
    code:

    someTextField_txt.htmlText = (newText.name); //info = variable in text file
    someTextField_txt2.htmlText = (newText.age); //info = variable in text file
    someTextField_txt3.htmlText = (newText.phone); //info = variable in text file


  8. #8
    Junior Member
    Join Date
    May 2006
    Posts
    10

    Info

    someTextField_txt.htmlText = (newText.info); //info = variable in text file


    Is there a way to make the info variable dynamic so I replace the text from a variable call elsewhere?

  9. #9
    Moderator whispers's Avatar
    Join Date
    Mar 2001
    Location
    CFA2h (respect the HEX)
    Posts
    12,755
    Im not really following you..

    but you could possible do something like:
    code:

    var textVar = newText.info; //info = variable in text file
    someTextField_txt.htmlText = (textVar);



    I mean the text file has to have a variable hard coded in it..(at least one)..

  10. #10
    Junior Member
    Join Date
    May 2006
    Posts
    10
    I've designed a course that has 2 dynamic text boxes onscreen, each one has an assigned variable that references my text file. I'd like to use a generic variable in the template and rather than renaming each mc I could change the variable dynamically in my actionscript using a counter.

    Sort of like info = "page" + counter; (Counter increments/decrements depending on page).

    So to recap, I can get your code to work, by replacing variable "info" with page1.

    But if I try and declare info = page1; and then run the code I get undefined. Is there a way to assign a value to info???

    Thanks for the response btw.

  11. #11
    Moderator whispers's Avatar
    Join Date
    Mar 2001
    Location
    CFA2h (respect the HEX)
    Posts
    12,755
    Sorry I still dont understand

    &info= is in the textFile...

    you want to be able to change what text file the textField loads?...or what info the textField reflects from inside the text file?

  12. #12
    Junior Member
    Join Date
    May 2006
    Posts
    10
    Here's a sample of my text.txt file:

    &title1=Introduction&
    &title2=Language Selection&
    &title3=Navigation&
    &title4=Introduction&
    &title5=Table of Contents&

    I want something that can load a variable from my text file into a mc. So I understand that - someTextField_txt.htmlText = (newText.title1); will load "Introduction" into my mc.

    However I'd like to use a variable to replace title1, so something like:

    var textVar = newText.title1;

    someTextField_txt.htmlText = (newText.textVar); //info = variable in text file
    But when I do this I get undefined.





    In my current setup each page has the variable in the dynamic text box, I don't want to do that.

  13. #13
    Junior Member
    Join Date
    May 2006
    Posts
    10
    Here's a sample of my text.txt file:

    &title1=Introduction&
    &title2=Language Selection&
    &title3=Navigation&
    &title4=Introduction&
    &title5=Table of Contents&

    I want something that can load a variable from my text file into a mc. So I understand that - someTextField_txt.htmlText = (newText.title1); will load "Introduction" into my mc.

    However I'd like to use a variable to replace title1, so something like:

    var textVar = newText.title1;

    someTextField_txt.htmlText = (newText.textVar); //info = variable in text file

    But when I do this I get undefined.

    I've almost given this up, Iam beginning to believe I can't replace the pointer to the text file with a variable. I see other people have posted similar to me and no-one has answered their queries.

    Part of the trouble is trying to sensibly explain this, I guess I'm failing!

  14. #14
    Moderator whispers's Avatar
    Join Date
    Mar 2001
    Location
    CFA2h (respect the HEX)
    Posts
    12,755
    well I believe you are correct.... the explaination is what is killing this thread.

    but.....this:
    code:

    var textVar = newText.title1;

    someTextField_txt.htmlText = (newText.textVar); //info = variable in text file


    would never work.. as you are defining newText twice.. in my example you would only need to use textVar,...NOT newText.newVar (as newText is already defined in the VAR)

    however...(and this might be because I am just not understanding)....but I think you have things messed up..
    &title1=Introduction&
    &title2=Language Selection&
    &title3=Navigation&
    &title4=Introduction&
    &title5=Table of Contents&
    your textFile should NOT have & at the end of the var value like that..ONLY when seperating each VAR

    but using your example...once you load that textFile...ALL variables in the textFile are accessable.

  15. #15
    Senior Member
    Join Date
    Feb 2006
    Posts
    198
    in the Flash 8 help panel, is said to use:
    varDynamicTextfielName=

    instead of
    &varDynamicTextfielName=

    Is the only reason for using the amersand sign: &, to seperate the variableNames?, or are there situation you must use the & sign being the first character at the first line.
    http://www.michaellobry.com specialized by and for Web Media Designers. Herein shown should be summarizings about Web Media Design (eg. all CSS rules, SHTML tags, How to PHP, Macromedia/ Adobe app how-tos, etc. Please e-mail yours to webmaster@michaellobry.com so that everybody learns)

  16. #16
    Moderator whispers's Avatar
    Join Date
    Mar 2001
    Location
    CFA2h (respect the HEX)
    Posts
    12,755
    no....you 'shouldnt' need to start with an &..but it shouldnt hurt either..

    and yes..you use an "&" to seperate the variables..... that way you can put many different variables in one text file.

  17. #17
    Senior Member
    Join Date
    Jun 2006
    Posts
    136
    sorry for bumping this.....i typed in the wrong one
    Last edited by drcolby; 07-17-2006 at 11:50 PM.
    If anyone can help me Please feel free it IM colbyneedshelp99 (AIM).

  18. #18
    Watch Your Head. GooseBump's Avatar
    Join Date
    Apr 2003
    Location
    The Resturant at the end of the Universe
    Posts
    431
    if you want to dynamicly change the contents of your dynamic text field all you'll need to do is this.

    At some point. say a button press you run the following code:

    First you load in your text file and define your variable, in this case it's the first variable from the text file.
    Code:
    loadText = new LoadVars();
    loadText.load("myText.txt");
    var myVariable = loadText.title1;
    Next you code your button
    Code:
    on (release){
    _root.myVariable = _root.loadText.title2;
    }
    Then the last step is to tie your dynamic text field to the variable. In the "Var" input box in the Properties panel for you dynamic text field you enter the variable "_root.myVariable". That should do it.

  19. #19
    Member
    Join Date
    Apr 2007
    Posts
    73
    Quote Originally Posted by whispers
    this example assumes that inside the textFile you have the "data" set up as:

    Quote:
    &info=your text here....your text here...your text here.....


    I'm missing something here (in reference to Whisper's first response)- where exactly does one put the above information? Inside the textFile...but...um...where is that?

  20. #20
    Moderator whispers's Avatar
    Join Date
    Mar 2001
    Location
    CFA2h (respect the HEX)
    Posts
    12,755
    sorry.. the above you quoted should be:

    &data=your text here....your text here...your text here.....
    not info.

    you need to MAKE a text file. if you want to load text form an EXTERNAL.txt file.. you need to create one for it to load/read.

    newText.txt is the name fo the textFiel you need to create.. save in same folder as your .swf

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