Need help with loading unproper textfile data

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


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


david    30
michael 40
john     50

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


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

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=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


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

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=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…:wink:

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

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

you should simply be able to go

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]


[/noparse] tags

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 :slight_smile:

Hi

Try this:


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

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

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

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);
bill||30
pete||40
bob||23
bubble'o||bill||40

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

tq again