A Flash Developer Resource Site

Results 1 to 7 of 7

Thread: Can't add space in text file. Help please

  1. #1
    Junior Member
    Join Date
    Sep 2006
    Posts
    29

    Can't add space in text file. Help please

    Hi

    The code below was kindly provided (dawsonk ) to help me create a random name selector for the classroom. It works great but it doesn't like a space between two words. So I can't copy and paste a list with name and surname. It comes out with nonsense characters in the space.

    Any ideas on how to remedy this?
    Thanks

    frame 1

    stop();

    var name = new Array();
    var colour = new Array();
    var letter = new Array();

    function getRandInfo(fileName, info) {
    var myLV = new LoadVars();
    myLV.onLoad = function(success) {
    if (success) {
    for (var i in myLV) {
    var tmpArray = escape(i).split("%0D%0A");
    break;
    }
    var infoArray = new Array();
    for (var i = 0; i<tmpArray.length; i++) {
    if (tmpArray[i].length != 0) {
    infoArray.push(tmpArray[i]);
    }
    }
    var count = Number(random(infoArray.length));
    info.push(infoArray[count]).toString();
    play()
    } else {
    info.push("error").toString();
    trace("Ooops there is something wrong - better check it out.");
    }
    };
    myLV.load(fileName);
    }


    getRandInfo('names.txt',name);

    frame 2


    stop();
    trace("Name: "+name);

    getRandInfo('colours.txt',colour);

    frame 3


    stop();
    trace("Colour: "+colour);

  2. #2
    :
    Join Date
    Dec 2002
    Posts
    3,518
    Code:
    trace("Name: "+unescape(name));

  3. #3
    Junior Member
    Join Date
    Sep 2006
    Posts
    29
    Thanks for your help(again!!)
    I tried this but still get, e.g. John%20Smith.
    I replaced

    stop();
    trace("Name: "+name);

    with the code you gave. Should I change anything else?

    Cheers

  4. #4
    :
    Join Date
    Dec 2002
    Posts
    3,518
    Nope, that should work.

  5. #5
    Junior Member
    Join Date
    Sep 2006
    Posts
    29
    Fiddled around with various things and still comes up with %20 in the space.
    I've attached a zip folder with the fla. and text file- I just slimmed it down to the one variable. I would be great if you had a chance take a look to see what I'm doing wrong. If not, thanks anyway for all your help on this.
    Attached Files Attached Files

  6. #6
    :
    Join Date
    Dec 2002
    Posts
    3,518
    Code:
    stop();
    var name = new Array();
    var colour = new Array();
    var letter = new Array();
    function getRandInfo(fileName, info) {
    	var myLV = new LoadVars();
    	myLV.onLoad = function(success) {
    		if (success) {
    			for (var i in myLV) {
    				var tmpArray = escape(i).split("%0D%0A");
    				break;
    			}
    			var infoArray = new Array();
    			for (var i = 0; i < tmpArray.length; i++) {
    				if (tmpArray[i].length != 0) {
    					infoArray.push(tmpArray[i]);
    				}
    			}
    			var count = Number(random(infoArray.length));
    			info.push(unescape(infoArray[count]) ).toString();
    			play();
    		}
    		else {
    			info.push("error").toString();
    			trace("Ooops there is something wrong - better check it out.");
    		}
    	};
    	myLV.load(fileName);
    }
    
    
    getRandInfo('names.txt',name);

  7. #7
    Junior Member
    Join Date
    Sep 2006
    Posts
    29
    So much appreciated! You are a very generous person.
    Cheers.

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