I have a problem kind of lost it…how to grouping the elements in array into 2 section/or put in 2 new array…
Ok the scenario is :I have several data retrieve from dtbase like in this as code
ActionScript Code:
[FONT=Courier New][LEFT][COLOR=#0000ff]stop[/COLOR][COLOR=#000000]([/COLOR][COLOR=#000000])[/COLOR];
[COLOR=#000000]var[/COLOR] getCusDt:[COLOR=#0000ff]LoadVars[/COLOR] = [COLOR=#000000]new[/COLOR] [COLOR=#0000ff]LoadVars[/COLOR]COLOR=#000000[/COLOR];
[COLOR=#000000]var[/COLOR] receCusDt:[COLOR=#0000ff]LoadVars[/COLOR] = [COLOR=#000000]new[/COLOR] [COLOR=#0000ff]LoadVars[/COLOR]COLOR=#000000[/COLOR];
receCusDt.[COLOR=#0000ff]onLoad[/COLOR] = loadCusDt;
loadBtn.[COLOR=#0000ff]onPress[/COLOR] = [COLOR=#000000]function[/COLOR] COLOR=#000000[/COLOR] [COLOR=#000000]{[/COLOR]
getCusDt.[COLOR=#000080]usr_name[/COLOR] = usrname.[COLOR=#0000ff]text[/COLOR];
getCusDt.[COLOR=#0000ff]sendAndLoad[/COLOR]COLOR=#000000[/COLOR];
[COLOR=#000000]}[/COLOR]
[COLOR=#808080]//////////////////////////////////////[/COLOR]
[COLOR=#000000]function[/COLOR] loadCusDtCOLOR=#000000[/COLOR][COLOR=#000000]{[/COLOR]
[COLOR=#0000ff]if[/COLOR]COLOR=#000000[/COLOR][COLOR=#000000]{[/COLOR]
info.[COLOR=#0000ff]text[/COLOR] = [COLOR=#0000ff]this[/COLOR].[COLOR=#0000ff]message[/COLOR];
[COLOR=#0000ff]for[/COLOR] [COLOR=#000000]([/COLOR][COLOR=#000000]var[/COLOR] i = [COLOR=#000080]0[/COLOR]; i<this.[COLOR=#000080]items[/COLOR]; i++[COLOR=#000000])[/COLOR] [COLOR=#000000]{[/COLOR]
dtCustomize = [COLOR=#0000ff]this[/COLOR][COLOR=#000000][[/COLOR][COLOR=#ff0000]“datacustomize”[/COLOR]+i[COLOR=#000000]][/COLOR];
plottingCOLOR=#000000[/COLOR];
usrname.[COLOR=#0000ff]text[/COLOR] = [COLOR=#ff0000]""[/COLOR];
[COLOR=#000000]}[/COLOR]
[COLOR=#000000]}[/COLOR][COLOR=#0000ff]else[/COLOR][COLOR=#000000]{[/COLOR]
info.[COLOR=#0000ff]text[/COLOR] = [COLOR=#0000ff]this[/COLOR].[COLOR=#0000ff]message[/COLOR];
[COLOR=#000000]}[/COLOR]
[COLOR=#000000]}[/COLOR]
[COLOR=#808080]////////////////plotting part////////////[/COLOR]
[COLOR=#000000]function[/COLOR] plottingCOLOR=#000000[/COLOR][COLOR=#000000]{[/COLOR]
[COLOR=#808080]//trace(dt);[/COLOR]
[COLOR=#000000]var[/COLOR] descriptor:[COLOR=#0000ff]Array[/COLOR] = [COLOR=#000000][[/COLOR][COLOR=#000000]][/COLOR];
[COLOR=#808080]//insert into array…[/COLOR]
descriptor = dt.[COLOR=#0000ff]split[/COLOR]COLOR=#000000[/COLOR];
[COLOR=#808080]//okay the problem is here…how to separate the dt to become 2 section 1 for mymc and for another 1 is for textholder section…meaning that I can separate into 2 section…[/COLOR]
[COLOR=#0000ff]trace[/COLOR]COLOR=#000000[/COLOR];
[COLOR=#808080]//output --> ,textholder02926100100fifin04courier newoxcc000018,mymc080101241243*[/COLOR]
[COLOR=#000000]}[/COLOR]
[/LEFT]
[/FONT]
It means I will get the long string like this from the database
|textholder0*29*26*100*100*fifin04*courier new*oxcc0000*18|mymc0*80*101*241*243
so my question is how to grouping it just like this
mcArr = [mymc0*80*101*241*243,mymc1*80*101*241*243]
textArr = [textholder0*29*26*100*100*fifin04*courier new*oxcc0000*18,textholder1*29*26*100*100*fifin04*courier new*oxcc0000*18]
from the long string…
You can use the split method of a string to group elements into an array.
Here’s an example considering your string.
str = "|textholder0*29*26*100*100*fifin04*courier new*oxcc0000*18|mymc0*80*101*241*243";
myData = new Array();
myData = str.split("|");
for (var x in myData) {
var tmpStr = myData[x];
myData[x] = tmpStr.split("*");
}
trace(myData[0][0]);// traces nothing because you have a first | so it's considered that the first element is empty
trace(myData[1][0]);// traces textholder0
trace(myData[2][3]);// traces 241
Good luck
PS. After I posted I’ve noticed the comma. You first split using the comma instead of the * sing and then split the results again using the * sign. I hope you got the ideea.
Hi…virusescu…
1stly thanks for ur reply…ok regarding the split and then put in array that’s 1st thing I done…before I raise up here…okay if I just split the long string and put in 1 array…the problem is…the length of the string will not static…sometime it can be 5/6 and so on…so how would i detect of the array if I just put all in 1 array only…?..anyhow I’ll dig it 1st…then I’ll come back if I have any issue…
Edit:so if I can categorize the elements in 2 categorize like
mcArr = [mymc0*80*101*241*243,mymc1*80*101*241*243,mymc2*80*101*241*243]
txtArr = [textholder0*29*26*100*100*fifin04*courier new*oxcc0000*18,textholder1*29*26*100*100*fifin04*courier new*oxcc0000*18]
so I’ll easily loop the array for attaching MC purposing…u know what I mean mate :devious:
thanks again…
Edit:so if I can categorize the elements in 2 categorize like
mcArr = [mymc0*80*101*241*243,mymc1*80*101*241*243,mymc2*80*101*241*243]
txtArr = [textholder0*29*26*100*100*fifin04*courier new*oxcc0000*18,textholder1*29*26*100*100*fifin04*courier new*oxcc0000*18]
so I’ll easily loop the array for attaching MC purposing…u know what I mean mate 
so how would i detect of the array if I just put all in 1 array only…?
I really don’t understand your problem/question. It’s called a multidimensionall array - notice the repeated access.
if I just split the long string and put in 1 array…the problem is…the length of the string will not static…sometime it can be 5/6 and so on
So what? Have you seen any numbers before the traces in my code example :)?
Hi…sorry for delay reply mate…1stly sorry if my question are still blur to u Ady…ok if I’m using ur method it’ll only trace individual elements array eg;
trace(myData[1][0]);// traces textholder0
trace(myData[2][0]);// traces mymc0
trace(myData[3][0]);// traces textholder1
trace(myData[4][0]);// traces mymc1
so which is hard for me to loop the array for attaching mc purposing later on…so what I after is how to put the textholder things into txtArr and mymc things into mcArr that’s all…eg;
txtArr = [textholder0*29*26*100*100*fifin04*courier new*oxcc0000*18,textholder1*29*26*100*100*fifin04*courier new*oxcc0000*18];
mcArr = [mymc0*80*101*241*243,mymc1*80*101*241*243];
so later on I can easily acces the 2 categorize array for attaching plotting mc purposing…hope u get it Ady…
tq again
ok if I’m using ur method it’ll only trace individual elements array eg;
That’s the whole point so that you can access individual properties after splitting your data.
Here’s an example with the data arranged in 2 different arrays.
str = "textholder0*29*26*100*100*fifin04*courier new*oxcc0000*18|mymc0*80*101*241*243|textholder1*25*23*90*90*fifin04*courier new*oxcc0000*18|mymc1*80*101*241*243";
myData = new Array();
myData = str.split("|");
for (var x in myData) {
var tmpStr = myData[x];
myData[x] = tmpStr.split("*");
}
// so now you have all the data arrangedn in the myData array.
// You can further arrange it in 2 separate arrays like this
var mcArr = new Array();
var textArr = new Array();
for (var x in myData) {
if (myData[x][0].indexOf("text")>=0) {
// means we have as the first element a string that contains "text";
// so we put it in the text Arr;
textArr.push(myData[x].slice());
} else {
mcArr.push(myData[x].slice());
}
}
delete myData;
for (var x in textArr) {
for (var y in textArr[x]) {
trace("textArr["+x+"] has y:"+y+" with value "+textArr[x][y]);
}
}
trace("---------------------");
for (var x in mcArr) {
for (var y in mcArr[x]) {
trace("mcArr["+x+"] has y:"+y+" with value "+mcArr[x][y]);
}
}
// this means that you can still trace individual elements easyer.
// if you would need to find out the second property of the first textholder
// you can easly access it like textArr[0][1]
Hope this helps
Hi…Ady…
it works now…thanks for ur help…mate…