PDA

View Full Version : Splitting text variable into an array


steveb1164
06-24-2004, 07:10 PM
In layer 1 I have the following code to pull the variable 'playerrank' from my ASP page:

myData = new LoadVars();
myData.onLoad = function() {
playerrank.text = this.playerrank;
};
myData.load("livedraftvar.asp");
stop();

In layer 2 I have the following code to split 'playerrank' into an array and enter each item into a list box:

var playerrankArray = new Array();
playerrankArray = playerrank.split(",");
for(i=0; i<8; i++) {
playerlist.addItem(playerrankArray[i]);
}

The list box comes up with 8 commas, that's it. If I put 'playerrank' into a dynamic text box, it comes up exactly how I want it. 102,204,209,308,489,518,555,698. Using playerrank.split(",") should put the eight elements into the array, then enter them into the list box. Why am I getting eight commas instead of the eight numbers. Thanks.

binkyboo
06-24-2004, 08:44 PM
maybe you're not targeting playerrank properly. try this:


playerrankArray = myData.playerrank.split(",")

steveb1164
06-25-2004, 12:00 AM
This didn't work. Any other ideas? Thanks.

tg
06-25-2004, 09:44 AM
myData = new LoadVars();
myData.onLoad = function(done) {
if(done){
playerrankArray = playerrank.split(",");
for(i=0; i<8; i++) {
playerlist.addItem(playerrankArray[i],null);
}
}
};
myData.load("livedraftvar.asp");


this will work if playerrank looks like &playerrank=1,2,3,4,5,6,7& coming from the asp file

annexion
06-25-2004, 04:13 PM
I'm using FMX 2004, but your problem may be the line:

playerlist.addItem(playerrankArray[i]);

In the latest version of Flash and the combobox component it should be:

playerlist.addItem({playerrankArray[i]});

Your data provider should be an array of objects. In your code it would make it an array of strings, which could potentially be causing the comma issue.

Again, I'm coming from the FMX 2004 paradigm, so excuse me if it doesn't work.

Good luck.