A Flash Developer Resource Site

Results 1 to 8 of 8

Thread: bringing in text from files

  1. #1
    Junior Member
    Join Date
    Feb 2005
    Location
    brisbane australia
    Posts
    19

    bringing in text from files

    How do I bring text from an external text file (text.txt) into a dynamic text box at for eg frame 6 (f6) in a movieclip (textMc) . I have researched this topic in 3 manuals and can't figure it out.
    tmj

  2. #2
    FK'n_dog a_modified_dog's Avatar
    Join Date
    Apr 2003
    Location
    "aaarf"
    Posts
    9,176
    Main timeline -
    lv = new LoadVars();
    lv.onLoad=function(){
    _level0.myVar = lv.myVar;
    };
    lv.load("text.txt");

    text.txt - myVar=hello&

    movieclip frame6 -
    myTextfield.text = _level0.myVar;

    something like that ?

  3. #3
    Moderator enpstudios's Avatar
    Join Date
    Jun 2001
    Location
    Tampa, Fl.
    Posts
    11,282
    Here is a .fla I put together a loooooooooooong time ago !!

    Zip File

  4. #4
    Between Flash & Flashkit timothye's Avatar
    Join Date
    Dec 2003
    Location
    Sweden
    Posts
    1,666
    it really depends on what type of external txt file your loading into the flash txtField..
    if your txtFile has &%#"! > and other characters then you can elimate URL encoding these in the txtFiel by using " onData " if your txtFiel is just regular characters then you can use onLoad . but it really depends on what your txtFiel contents are ..i can show you how i load in external xtx files depending on the contents .
    this script i use when ther are no special characters =)(/&%/%¤#"¤
    Code:
    //system use code page . will display characters such as ÄÖÅäöå 
    System.useCodepage = true;
    load_btn.onRelease = function() {
    	var myVar:LoadVars = new LoadVars();
    	myVar.load("load_txt.txt");
    	myVar.onLoad = function(success:Boolean):Void  {
    		if (success) {
    			load_txt.htmlText = this.load_txt;
    			trace("loaded");
    		} else {
    			trace("not loaded");
    		}
    	};
    };
    and this 1 is for special characters

    Code:
    //load vars onData you dont have to URL encode
    var my_lv:LoadVars = new LoadVars();
    my_lv.onData = function(src:String) {
    	if (src == undefined) {
    		trace("Error loading content.");
    	} else {
    		my_txt.text = src;
    	}
    };
    my_lv.load("my_txt.txt");
    on the code that uses on data , you do NOT NEED to include my_txt= in the external txt file as the first line ..
    so much more to type . but i think this will help you on your way , or atleast i hope it does .

    i hope this helps you in your external txtFile quest .
    Cheers M8
    T
    Last edited by timothye; 01-26-2006 at 04:54 PM.
    I want to learn .
    wannabe flasher [ Actionscript 2.0 ]

  5. #5
    Junior Member
    Join Date
    Feb 2005
    Location
    brisbane australia
    Posts
    19

    bringing external text

    [QUOTE=estudioworks]Here is a .fla I put together a loooooooooooong time ago !!
    Dear Estudioworks... your example may have put me on the right track but I still may not be naming things properly. Would you be willing to look at what I'm trying to do in context: http://www.teresajordan.id.au/painting/painting.htm (click posters & then the cathedral button.)
    this is the code I've used so far
    loadVariablesNum("text/enter.txt",0);
    loadMovie("posterimages/harrass.jpg", picMc);
    txtstageMc.gotoAndStop("harrass");
    cathedralBu.onRelease = function() {
    loadMovie("posterimages/cathedral.jpg", picMc);
    txtstageMc.gotoAndStop("cathedral");
    loadVariablesNum("text/enter.txt",0);
    };

    etc
    tmj

  6. #6
    Moderator enpstudios's Avatar
    Join Date
    Jun 2001
    Location
    Tampa, Fl.
    Posts
    11,282
    Make sure the text field you are trying to use is Dynamic, has an instance name, also put this in your text file before your text

    Code:
    &textMessage=
    Last edited by enpstudios; 01-26-2006 at 08:47 PM.

  7. #7
    Junior Member
    Join Date
    Feb 2005
    Location
    brisbane australia
    Posts
    19
    Hi estudioworks,
    thanks so much for helping!
    I have called the text field instance cathedralTxt
    I have started the text file like this:-
    <cathedralTxt
    &content=etc>
    (is this what you mean?) the html tags which don't show here

    Where would I put the instance name (cathedralTxt) in the action script code below?

    loadVariablesNum("text/enter.txt",0);
    tmj

  8. #8
    Moderator enpstudios's Avatar
    Join Date
    Jun 2001
    Location
    Tampa, Fl.
    Posts
    11,282
    You need to do this:

    Code:
    cathedralTxt.text = &content

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