-
Senior Member
split() command :: arrays?
I cannot figure out how to get an indexed array from a delimited string for the life of me. Someone told me to do this
Code:
array=delimitedString.split("|");
since i used the '|' as my delimiter when sending the variable to flash. but when i run this, all it does is give me this:
say string = "value1|value2|value3|value4"
i do trace(array[0]) i get "undefined". same for other index numbers. but if i do trace(array) i get value1,value2,value3,value4
what the Heck!!! i am so fed up with this. this is all that has been holding me up for hours!
TIA for any help you can offer
FASCISM DOESN'T ALWAYS LOOK LIKE ADOLF HITLER.
-
This works for me.
code:
delimitedString = "234|24|532|7|45|235";
thearray=delimitedString.split("|");
trace( thearray[0] );
(traces 234)
If it doesn't work try using the Debugger and looking at the variables themselves.
-
Senior Member
Does that work in flash MX? i am doing exactly that. and it doesn't work for me. exact same code. I made a test movie and all it does is make a delimited stringd then assign an array with delimitedString.split("|") and i can't use the array indexes. I don't understand. I did it at work and at home. two separate computers, two separate copies of Flash MX and neither worked.
FASCISM DOESN'T ALWAYS LOOK LIKE ADOLF HITLER.
-
Originally posted by 7year
Does that work in flash MX? i am doing exactly that. and it doesn't work for me. exact same code. I made a test movie and all it does is make a delimited stringd then assign an array with delimitedString.split("|") and i can't use the array indexes. I don't understand. I did it at work and at home. two separate computers, two separate copies of Flash MX and neither worked.
just 1 question... are u loading an external data file?
-
Senior Member
i am actually using data returned from php which is sent in the format &arrayName=value1|value2|value3|value4, but that shouldn't matter because all the data taken in from LoadVariables is taken as strings. I also tried making an empty flash file that only had the following code:
stringVar="value1|value2|value3|value4";
arrayVar=stringVar.split("|");
trace(arrayVar[0]);
i get undefined for the trace value
if i do trace(arrayVar) i get this value1,value2,value3,value4
all it does is replace the pipe symbols '|' to commas.
FASCISM DOESN'T ALWAYS LOOK LIKE ADOLF HITLER.
-
Senior Member
ok, heres a new update. I got it to return the values in a trace, if i assign them manually. Now, i have a new problem, though the values are available through trace, they don't come up in a dynamic text field. what the hell!!!! Is it making an array of strings, or not?
FASCISM DOESN'T ALWAYS LOOK LIKE ADOLF HITLER.
-
here's what i would do...
code:
var _f = new LoadVars();
_f.load ("yourScript.php");
_f.onLoad = function () {
myArray = this.arrayName;
arrayVar = myArray.split("|");
for (i in arrayVar) trace (arrayVar[i]);
}
And to display it...
yourTextField.text = arrayVar[index]
-
Senior Member
ok, some progress!!! i got the array[index] to display in a textfield, but it only works when the text for the textfield is assigned(fieldName.test=arrayName[0]) inside of the onLoad function. This is so hard! AS sucks compared to other languages
FASCISM DOESN'T ALWAYS LOOK LIKE ADOLF HITLER.
-
Senior Member
i also tried assigning a new _global array to the same variables as the one inside the onLoad function, but i cant access those either
FASCISM DOESN'T ALWAYS LOOK LIKE ADOLF HITLER.
-
Originally posted by 7year
ok, some progress!!! i got the array[index] to display in a textfield, but it only works when the text for the textfield is assigned(fieldName.test=arrayName[0]) inside of the onLoad function. This is so hard! AS sucks compared to other languages
u can only display your data when it was fully loaded... thats why u can have it displayed inside the onLoad event.
code:
/* ******
file.txt
varSome=1|2|3|4
*/
var a = new LoadVars();
a.load ("file.txt");
a.onLoad = function () { trace (this.varSome) }
// returns 1|2|3|4
trace (varSome);
// returns undefined coz it will be executed b4 u load your txt file (or php script).
Following that clue u need to trigger your event inside the onLoad function...
-
Senior Member
i did fix it in fact, and that was the problem. I did this.
the php script returns it like this now:
&arrayName=value1|value2|value3|value4&completeHom eLoad=yes
then i did this on frame 3:
if(completeHomeLoad!="yes") {
gotoAndPlay(2)
}
when on frame four i set the text field values. works like a charm. Thank you everyone for helping me reach a conclusion.
FASCISM DOESN'T ALWAYS LOOK LIKE ADOLF HITLER.
Posting Permissions
- You may not post new threads
- You may not post replies
- You may not post attachments
- You may not edit your posts
-
Forum Rules
|
Click Here to Expand Forum to Full Width
|