A Flash Developer Resource Site

Results 1 to 3 of 3

Thread: Import .txt file as a array! (multidimensional)

  1. #1
    A Flurry of Activity
    Join Date
    Aug 2005
    Posts
    103

    Import .txt file as a array! (multidimensional)

    Ok- this is a program for self use, so i can just have the outside .txt file in the same folder as the .fla (i know this.)

    So- how to format the .txt file so that when i do this:

    Code:
    loadVarsText = new LoadVars();
    loadVarsText.load("Rapsodygap.txt");
    loadVarsText.onLoad = function(success) {
    	if (success) {
    		trace(this.gap);
    	}
    }
    firstdata = this.gap[0,1]
    I want rapsodygap.txt to look and do something like this:
    Code:
    &variablename= [[1.307,1],[1.407,2],[1.503,3]]
    Practical aspect- i'm getting the program to import this text file, and i'm gonna do some calculations with the arrays (first number is a time (in ms) 2nd number is how many beats this is away from the last one.)

    its a bpm caculator, but VERY EXACT, for when checking the waveform of audio.

    I could do it with calculator, but the point is that i'm about to attempt a 17 minute song, and so i need a program to do the calculations. I HAVE IT ALL CODED NOW ALL I NEED IS TO IMPORT MY ARRAYS!!!! *sighs*
    maximum width 300 no more maximum hieght 40 no more not interchangable

  2. #2
    Senile member! :)
    Join Date
    Dec 2001
    Location
    Saunaswamp (transl)
    Posts
    2,296
    When loading external textfiles there's only one datatype available and that is the String datatype. So you need to form the data so it can be roken apart after it has loaded.

    E.g: Start by doing your textfile like this:

    Code:
    &variablename1=1.307,1&variablename2=1.407,2&variablename3=1.503,3
    Then you parse it after it's loaded like this:
    Code:
    var gap = new Array();
    loadVarsText = new LoadVars();
    loadVarsText.load("Rapsodygap.txt");
    loadVarsText.onLoad = function(success) {
    	var tmp;
    	var i = 1;
    	if (success) {
    		while(this["variablename" + i] != undefined) {
    			tmp = this["variablename" + i].split(",");
    			gap.push([Number(tmp[0]), Number(tmp[1])])
    			i++
    		}
    	}
    }
    /Mirandir

  3. #3
    A Flurry of Activity
    Join Date
    Aug 2005
    Posts
    103
    *sigh* that was no good (too cumbersome to format notepad file for broad range of users (me).), so i'm just editing the code (in array format) in notepad, then copy and pasting code into the program itself XD oh well it works! same result! lol
    maximum width 300 no more maximum hieght 40 no more not interchangable

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