A Flash Developer Resource Site

Results 1 to 3 of 3

Thread: load multiple files into single array

  1. #1
    Junior Member
    Join Date
    Jan 2007
    Posts
    25

    load multiple files into single array

    hi, I have two ordinary .txt files with several lines of text in both of them. What I want to do is to load the text of both files into a single array, is that possible?
    note: the number of text-files will vary depending on user input.

    at the moment I have:

    PHP Code:
    fileNames = ["text1.txt""text2.txt"]; 
    and I know you can use loadVariablesNum if you have only one file to load, but as soon as I've got two or more it just overwrites the old loaded text instead of adding it to the array.

    any solutions?
    thanks

  2. #2
    Junior Member
    Join Date
    Jan 2007
    Posts
    25
    anyone?

  3. #3
    FK'n_dog a_modified_dog's Avatar
    Join Date
    Apr 2003
    Location
    "aaarf"
    Posts
    9,176
    use multiple LoadVars objects.

    can you make use of this simplified example ?
    PHP Code:
    // text1.txt -- &vars=a,b,c,d&
    // text2.txt -- &vars=e,f,g,h&

    fileNames = ["text1.txt""text2.txt"];
    len fileNames.length;
    arr = [];

    for(var 
    n=0;n!=len;n++){
    this["lv"+n] = new LoadVars();
    this["lv"+n].load(fileNames[n]);
    this["lv"+n].onLoad = function(){
    arr.push(this.vars.split(","));
    showArray();
    }
    }

    function 
    showArray(){
    trace("--------");
    for(var 
    p=0;p!=arr.length;p++){
    len2 arr[p].length;
    for(var 
    q=0;q!=len2;q++){
    trace("arr["+p+"]["+q+"] = "+arr[p][q]);
    }
    }
    };

    /* - produces this array -

    _level0.arr = [object #2, class 'Array'] [
        0:[object #3, class 'Array'] [
          0:"a",
          1:"b",
          2:"c",
          3:"d"
        ],
        1:[object #4, class 'Array'] [
          0:"e",
          1:"f",
          2:"g",
          3:"h"
        ]

    */ 
    hth

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