dcsimg
A Flash Developer Resource Site

Results 1 to 4 of 4

Thread: importing data

  1. #1
    Electrical Engineer
    Join Date
    Aug 2003
    Location
    Indiana, USA
    Posts
    122

    importing data

    I have a small matrix of imformation that I am using in my flash project. This data may occasionaly change and I want to make it easy for the user to change the data either in excel or a similar file.

    Say I have 10 columns and 10 rows of information. Can I have this in an excel file and have flash use the data in actionscripts?

    I don't even know how to get started... Do I use excel, a text file, something else? Do I read it in by a row at a time, a line a time? Do I read it into arrays?

    Please help me get started. Thanks.


    -Nathan

  2. #2
    Senior Member
    Join Date
    Aug 2002
    Location
    Dublin, Ireland
    Posts
    1,749
    It is easy to save text files as either tab or comma separated values from Excel.
    However, Flash won't know what to do with these values unless you edit the text files to start with a variable name, eg Excel saves:
    Code:
    R1C1,R1C2,R1C3,R1C4,R1C5,R1C6,R1C7,R1C8,R1C9,R1C10
    R2C1,R2C2,R2C3,R2C4,R2C5,R2C6,R2C7,R2C8,R2C9,R2C10
    R3C1,R3C2,R3C3,R3C4,R3C5,R3C6,R3C7,R3C8,R3C9,R3C10
    R4C1,R4C2,R4C3,R4C4,R4C5,R4C6,R4C7,R4C8,R4C9,R4C10
    R5C1,R5C2,R5C3,R5C4,R5C5,R5C6,R5C7,R5C8,R5C9,R5C10
    R6C1,R6C2,R6C3,R6C4,R6C5,R6C6,R6C7,R6C8,R6C9,R6C10
    R7C1,R7C2,R7C3,R7C4,R7C5,R7C6,R7C7,R7C8,R7C9,R7C10
    R8C1,R8C2,R8C3,R8C4,R8C5,R8C6,R8C7,R8C8,R8C9,R8C10
    R9C1,R9C2,R9C3,R9C4,R9C5,R9C6,R9C7,R9C8,R9C9,R9C10
    R10C1,R10C2,R10C3,R10C4,R10C5,R10C6,R10C7,R10C8,R10C9,R10C10
    You need to add a variable name at the start:
    Code:
    matrix=R1C1,R1C2,R1C3,R1C4,R1C5,R1C6,R1C7,R1C8,R1C9,R1C10
    R2C1,R2C2,R2C3,R2C4,R2C5,R2C6,R2C7,R2C8,R2C9,R2C10
    R3C1,R3C2,R3C3,R3C4,R3C5,R3C6,R3C7,R3C8,R3C9,R3C10
    R4C1,R4C2,R4C3,R4C4,R4C5,R4C6,R4C7,R4C8,R4C9,R4C10
    R5C1,R5C2,R5C3,R5C4,R5C5,R5C6,R5C7,R5C8,R5C9,R5C10
    R6C1,R6C2,R6C3,R6C4,R6C5,R6C6,R6C7,R6C8,R6C9,R6C10
    R7C1,R7C2,R7C3,R7C4,R7C5,R7C6,R7C7,R7C8,R7C9,R7C10
    R8C1,R8C2,R8C3,R8C4,R8C5,R8C6,R8C7,R8C8,R8C9,R8C10
    R9C1,R9C2,R9C3,R9C4,R9C5,R9C6,R9C7,R9C8,R9C9,R9C10
    R10C1,R10C2,R10C3,R10C4,R10C5,R10C6,R10C7,R10C8,R10C9,R10C10
    You can then use:
    code:

    mtxt = new LoadVars();
    mtxt.load("c:\\temp\\matrix.txt");
    mtxt.onLoad = function() {
    // Split the matrix into rows
    matrix = this.matrix.split("\r\n");
    // Weed out any blank rows from the end of the matrix
    var i = matrix.length-1;
    while (matrix[i].length == 0 && i>-1) {
    matrix.pop();
    i--;
    }
    // For each row, split it into columns
    for (i in matrix) {
    matrix[i] = matrix[i].split(",");
    }
    };


    to create a matrix array. The row and column numbers are zero indexed, so matrix[0][5] returns the sixth item in the first row.

  3. #3
    <<MXian>> memon2k's Avatar
    Join Date
    Nov 2001
    Location
    C:\Program Files\Macromedia\Flash MX
    Posts
    148
    Hey..
    i came across this HTML component, which takes in the data as XML file and populates a table with colums and rown defined in the XML file. you can get it from www.flashcomponents.net probably... hope it solves the problem. it is called HTML UI Components.
    [aLi]-Ur fUtUrE dEPeNdS uPoN uR dReaMs.. So GoTo SlEeP~!

  4. #4
    Electrical Engineer
    Join Date
    Aug 2003
    Location
    Indiana, USA
    Posts
    122
    Where do add a variable name at the start at? Do I need to have this in the coma separated valve file or in my actionscript?

    Thanks

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