# Need help with loading unproper textfile data

**URL:** <https://forum.kirupa.com/t/need-help-with-loading-unproper-textfile-data/264127>\
**Category:** Uncategorized\
**Created:** [June 23, 2008, 1:57pm UTC](https://forum.kirupa.com/t/need-help-with-loading-unproper-textfile-data/264127 "2008-06-23T13:57:48Z")\
**Posts on this page:** 12\
**Page:** 1

<div class="post-metadata">

**Author:** ![pixeldude](https://avatars.discourse-cdn.com/v4/letter/p/57b2e6/32.png) [@pixeldude](https://forum.kirupa.com/u/pixeldude)\
**Post date:** [June 23, 2008, 1:57pm UTC](https://forum.kirupa.com/t/need-help-with-loading-unproper-textfile-data/264127/1 "2008-06-23T13:57:48Z")

</div>

Hi …

Okay just a quick shoot here…okay I try to refresh updated textfile data every 2 seconds and it’s works ok if I’m using normal delimiters and proper data arrangement in textfile such as

//in textfile

```auto

david||30
michael||40
john||50

```

but my problem is how to load the data from textfile which store not in proper way and using ‘space’ as a delimiters

```auto

david 30
michael 40
john 50

```

so here’s ar emy attempt code so far stil returning undefined

```auto

stop();

var lv:LoadVars = new LoadVars();
var someArr:Array = new Array();

//counting purposing
var counter:Number = 0;

function refreshData():Void{
    lv.onLoad = function(mydata){
        
        trace(mydata);//output true
        itemlist = mydata.split("");
        trace(itemlist);//output undefined
        for(var i=0;i<itemlist.length;i++){
            someArr.push([itemlist*[0],itemlist*[1]]);
        }
        trace(someArr);
        /*
        if(success){
            counter++;
            trace("succes open textfile and opening textfiel for the"+" "+counter+" "+"time");
        }else{
            trace("fail open textfile");
        }
        */
    }
    lv.load("thedata.txt");
}

var loadData = setInterval(refreshData,2000);

```

So really need help with it…any help are really appreciated…tq in advanced

---

<div class="post-metadata">

**Author:** ![randomagain](https://avatars.discourse-cdn.com/v4/letter/r/35a633/32.png) [@randomagain](https://forum.kirupa.com/u/randomagain)\
**Post date:** [June 23, 2008, 2:05pm UTC](https://forum.kirupa.com/t/need-help-with-loading-unproper-textfile-data/264127/2 "2008-06-23T14:05:15Z")

</div>

I can answer this so it aint that advanced

you want seperate text fields for each element

or just create a space where the deliminators were?

---

<div class="post-metadata">

**Author:** ![pixeldude](https://avatars.discourse-cdn.com/v4/letter/p/57b2e6/32.png) [@pixeldude](https://forum.kirupa.com/u/pixeldude)\
**Post date:** [June 23, 2008, 2:48pm UTC](https://forum.kirupa.com/t/need-help-with-loading-unproper-textfile-data/264127/3 "2008-06-23T14:48:11Z")

</div>

[quote=randomagain;2347610]I can answer this so it aint that advanced

you want seperate text fields for each element

or just create a space where the deliminators were?[/quote]

yes…I want tyo push the data into my array such as

```auto

myArr.push([1st elemnt,2nd element]);

```

here’s are my textfile format just now

user1 30  
user2 40  
user3 50  
user4 60

tq for ur time

---

<div class="post-metadata">

**Author:** ![randomagain](https://avatars.discourse-cdn.com/v4/letter/r/35a633/32.png) [@randomagain](https://forum.kirupa.com/u/randomagain)\
**Post date:** [June 23, 2008, 3:20pm UTC](https://forum.kirupa.com/t/need-help-with-loading-unproper-textfile-data/264127/4 "2008-06-23T15:20:27Z")

</div>

sorry but can’t help resist asking… why not xml?

this way you need String stuff

subString(start,end)  
indexOf(start, [“id”]);

to seperate the two strings, you need an ID at the start and end of each bit, so you can zoom in as it were  
and get the variable you want

\*\*xml is easier because you can just create seperate elements \*\*

---

<div class="post-metadata">

**Author:** ![pixeldude](https://avatars.discourse-cdn.com/v4/letter/p/57b2e6/32.png) [@pixeldude](https://forum.kirupa.com/u/pixeldude)\
**Post date:** [June 23, 2008, 11:57pm UTC](https://forum.kirupa.com/t/need-help-with-loading-unproper-textfile-data/264127/5 "2008-06-23T23:57:47Z")

</div>

[quote=randomagain;2347671]sorry but can’t help resist asking… why not xml?

this way you need String stuff

subString(start,end)  
indexOf(start, [“id”]);

to seperate the two strings, you need an ID at the start and end of each bit, so you can zoom in as it were  
and get the variable you want

\*\*xml is easier because you can just create seperate elements \*\*[/quote]

Answering ur queations ok actually my attempt is just to display result and update textfile data using flash only nothing fancy about it…why not using XML? it is because I write the textfile using C++ so the processing also happens in C++… using Flash as a medium for visualise result purposing only…anyway tq mate…for ur times…😉

---

<div class="post-metadata">

**Author:** ![nathan99](https://avatars.discourse-cdn.com/v4/letter/n/96bed5/32.png) [@nathan99](https://forum.kirupa.com/u/nathan99)\
**Post date:** [June 24, 2008, 1:32am UTC](https://forum.kirupa.com/t/need-help-with-loading-unproper-textfile-data/264127/6 "2008-06-24T01:32:36Z")

</div>

I havent used text files for ages. BUT I think if you set it up like this:

```auto
&bob=0&&bill=3&&pete=4&

```

you should simply be able to go

```auto
stop();

var lv:LoadVars = new LoadVars();
//counting purposing
var counter:Number = 0;
function refreshData():Void {
	lv.onLoad = function(success:Boolean):Void {
		if (success) {
			trace("Bob: "+this.bob);
			trace("Pete: "+this.pete);
			trace("Bill: "+this.bill);
		} else {
			trace("data couldn't load :( </3");
		}
	};
	lv.load("thedata.txt");
}

var loadData = setInterval(refreshData, 2000);

```

also, use the [noparse]

```auto

```

[/noparse] tags

---

<div class="post-metadata">

**Author:** ![pixeldude](https://avatars.discourse-cdn.com/v4/letter/p/57b2e6/32.png) [@pixeldude](https://forum.kirupa.com/u/pixeldude)\
**Post date:** [June 24, 2008, 1:43am UTC](https://forum.kirupa.com/t/need-help-with-loading-unproper-textfile-data/264127/7 "2008-06-24T01:43:46Z")

</div>

hi nathan99…  
thanks for the reply nathan…but frankly speaking …I really not having issues with proper data arrangement in textfile only with raw data only…I mean not proper save in tetxfile like example I provide previously…anyway thanks for ur concern mate 🙂

---

<div class="post-metadata">

**Author:** ![Nattis](https://avatars.discourse-cdn.com/v4/letter/n/f0a364/32.png) [@Nattis](https://forum.kirupa.com/u/Nattis)\
**Post date:** [June 24, 2008, 7:07am UTC](https://forum.kirupa.com/t/need-help-with-loading-unproper-textfile-data/264127/8 "2008-06-24T07:07:48Z")

</div>

Hi

Try this:

```auto

stop();

var lv:LoadVars = new LoadVars();
var someArr:Array = new Array();

//counting purposing
var counter:Number = 0;

function refreshData():Void{
    lv.onData = function(mydata){
        
        itemlist = mydata.split("
");
        
        for(var i=0;i<itemlist.length;i++){
            someArr.push(itemlist*.split(" "));
        }
        trace(someArr[0][1]);
        /*
        if(success){
            counter++;
            trace("succes open textfile and opening textfiel for the"+" "+counter+" "+"time");
        }else{
            trace("fail open textfile");
        }
        */
    }
    lv.load("thedata.txt");
}

var loadData = setInterval(refreshData,2000);

```

It should work if your textfile looks as in you latest post, with only one space as separator and no other spaces.

-Nattis

---

<div class="post-metadata">

**Author:** ![pixeldude](https://avatars.discourse-cdn.com/v4/letter/p/57b2e6/32.png) [@pixeldude](https://forum.kirupa.com/u/pixeldude)\
**Post date:** [June 25, 2008, 2:09am UTC](https://forum.kirupa.com/t/need-help-with-loading-unproper-textfile-data/264127/9 "2008-06-25T02:09:05Z")

</div>

Thanks nattis for ur concern …I just got it working now…🙂 anyway thanks for ur time…

---

<div class="post-metadata">

**Author:** ![pixeldude](https://avatars.discourse-cdn.com/v4/letter/p/57b2e6/32.png) [@pixeldude](https://forum.kirupa.com/u/pixeldude)\
**Post date:** [June 26, 2008, 11:52pm UTC](https://forum.kirupa.com/t/need-help-with-loading-unproper-textfile-data/264127/10 "2008-06-26T23:52:42Z")

</div>

Hi again…

I guess my problem still not solved and I’ve being spend and a days to figure out…but still unsuccessfull…the data in textfile being loaded properly…but the problem is now it do tracing the undefined value as well so when I push the value in array it will output the array length as 5 value for this textfile format:

**david 30  
michael 40  
john 50**

all data being separated for one space only  
and here’s my attempt code so far…  
ActionScript Code:  
[LEFT][COLOR=#0000FF]stop[/COLOR]COLOR=#000000[/COLOR];

[COLOR=#000000] **var** [/COLOR] mydata:[COLOR=#0000FF]Array[/COLOR] = [COLOR=#000000] **new** [/COLOR] [COLOR=#0000FF]Array[/COLOR]COLOR=#000000[/COLOR];  
[COLOR=#000000] **var** [/COLOR] holder:[COLOR=#0000FF]MovieClip[/COLOR] = [COLOR=#0000FF]this[/COLOR].[COLOR=#0000FF]createEmptyMovieClip[/COLOR]COLOR=#000000[/COLOR];

[COLOR=#000000] **var** [/COLOR] lv:[COLOR=#0000FF]LoadVars[/COLOR] = [COLOR=#000000] **new** [/COLOR] [COLOR=#0000FF]LoadVars[/COLOR]COLOR=#000000[/COLOR];  
lv.[COLOR=#0000FF]onData[/COLOR] = [COLOR=#000000] **function** [/COLOR]COLOR=#000000[/COLOR][COLOR=#000000]{[/COLOR]  
mydata = [COLOR=#000000] **new** [/COLOR] [COLOR=#0000FF]Array[/COLOR]COLOR=#000000[/COLOR];  
[COLOR=#000000] **var** [/COLOR] [COLOR=#0000FF]list[/COLOR] = rawdata.[COLOR=#0000FF]split[/COLOR][COLOR=#000000]([/COLOR][COLOR=#FF0000]"[COLOR=#000099] **\r** [/COLOR][COLOR=#000099]\*\*  
\*\*[/COLOR]"[/COLOR][COLOR=#000000])[/COLOR];  
[COLOR=#0000FF]trace[/COLOR]COLOR=#000000[/COLOR];  
[COLOR=#0000FF]for[/COLOR][COLOR=#000000]([/COLOR][COLOR=#000000] **var** [/COLOR] i=[COLOR=#000080]0[/COLOR];i\<list.[COLOR=#0000FF]length[/COLOR];i++[COLOR=#000000])[/COLOR][COLOR=#000000]{[/COLOR]  
[COLOR=#000000] **var** [/COLOR] line = [COLOR=#0000FF]list[/COLOR][COLOR=#000000][[/COLOR]i[COLOR=#000000]][/COLOR];  
[COLOR=#000000] **var** [/COLOR] [COLOR=#0000FF]array[/COLOR] = line.[COLOR=#0000FF]split[/COLOR][COLOR=#000000]([/COLOR][COLOR=#FF0000]" "[/COLOR][COLOR=#000000])[/COLOR];  
[COLOR=#000000] **var** [/COLOR] nama:[COLOR=#0000FF]Object[/COLOR] = [COLOR=#0000FF]array[/COLOR].[COLOR=#000080]shift[/COLOR]COLOR=#000000[/COLOR];  
[COLOR=#000000] **var** [/COLOR] numb:[COLOR=#0000FF]Object[/COLOR] = [COLOR=#0000FF]array[/COLOR].[COLOR=#0000FF]pop[/COLOR]COLOR=#000000[/COLOR];  
[COLOR=#808080]_//trace(“line number :”+i+" name :"+nama+" number :"+numb);_[/COLOR]  
mydata.[COLOR=#0000FF]push[/COLOR]COLOR=#000000[/COLOR];  
[COLOR=#000000]}[/COLOR]  
[COLOR=#0000FF]trace[/COLOR]COLOR=#000000[/COLOR];—\>\<b\>will output [COLOR=#000080]5[/COLOR] item eventhough there is [COLOR=#000080]3[/COLOR] value only [COLOR=#0000FF]in[/COLOR] tetxfile\</b\>  
attachMCCOLOR=#000000[/COLOR];  
[COLOR=#000000]}[/COLOR]

[COLOR=#000000] **function** [/COLOR] refreshDataCOLOR=#000000[/COLOR]:[COLOR=#0000FF]Void[/COLOR][COLOR=#000000]{[/COLOR]  
lv.[COLOR=#0000FF]load[/COLOR]COLOR=#000000[/COLOR];  
[COLOR=#000000]}[/COLOR]

[COLOR=#000000] **var** [/COLOR] loadData = [COLOR=#0000FF]setInterval[/COLOR]COLOR=#000000[/COLOR];

[COLOR=#000000] **function** [/COLOR] attachMCCOLOR=#000000[/COLOR]:[COLOR=#0000FF]Void[/COLOR][COLOR=#000000]{[/COLOR]  
[COLOR=#0000FF]trace[/COLOR]COLOR=#000000[/COLOR];  
[COLOR=#0000FF]for[/COLOR][COLOR=#000000]([/COLOR][COLOR=#000000] **var** [/COLOR] i [COLOR=#0000FF]in[/COLOR] Arr[COLOR=#000000])[/COLOR][COLOR=#000000]{[/COLOR]  
[COLOR=#000000] **var** [/COLOR] mc = holder.[COLOR=#0000FF]attachMovie[/COLOR]COLOR=#000000[/COLOR];  
mc.[COLOR=#0000FF]\_x[/COLOR] = [COLOR=#000080]50[/COLOR]+mc.[COLOR=#0000FF]\_width[/COLOR]\*i;  
mc.[COLOR=#0000FF]\_y[/COLOR] = [COLOR=#000080]100[/COLOR];  
[COLOR=#000000]}[/COLOR]  
[COLOR=#000000]}[/COLOR]  
[/LEFT]

so any help are really appreciated guys…thanks in advanced

---

<div class="post-metadata">

**Author:** ![nathan99](https://avatars.discourse-cdn.com/v4/letter/n/96bed5/32.png) [@nathan99](https://forum.kirupa.com/u/nathan99)\
**Post date:** [June 27, 2008, 12:19am UTC](https://forum.kirupa.com/t/need-help-with-loading-unproper-textfile-data/264127/11 "2008-06-27T00:19:55Z")

</div>

```auto
stop();
var lv:LoadVars = new LoadVars();
var rawData:Array = [];
var sortedData:Array = [];
//counting purposing
var counter:Number = 0;
function viewSortedData():Void {
	for (var i in sortedData) {
		trace("sortedData for "+i+": "+sortedData*);
	}
}
function sortData(myData:String, array:Array):Array {
	var sortedData:Array = [];
	array = myData.split("
");
	for (var i in array) {
		var tmp:Array = array*.split("||");
		sortedData[tmp[0]] = tmp[tmp.length-1];
	}
	return sortedData;
}
function refreshData():Void {
	lv.onLoad = function(success:Boolean):Void {
		if (success) {
			sortedData = sortData(this, rawData);
			viewSortedData();
		} else {
			trace("data couldn't load :( </3");
		}
	};
	lv.load("thedata.txt");
}
var loadData = setInterval(refreshData, 2000);

```

```auto
bill||30
pete||40
bob||23
bubble'o||bill||40

```

---

<div class="post-metadata">

**Author:** ![pixeldude](https://avatars.discourse-cdn.com/v4/letter/p/57b2e6/32.png) [@pixeldude](https://forum.kirupa.com/u/pixeldude)\
**Post date:** [June 30, 2008, 3:03am UTC](https://forum.kirupa.com/t/need-help-with-loading-unproper-textfile-data/264127/12 "2008-06-30T03:03:12Z")

</div>

Okay…thkns for the wondeful code nathan99 it works liek a charm now…🙂

tq again
