"Parse" of the array

All right, it’s getting hot in here!

I load an array from a txt/asp/php ect… file into my fla.

The file looks like this:

216|net.5.mp3|world
& 214|rock.net.3.mp3|Family
& 217|net.6.mp3|world
& 218|net.7.mp3|rap
& 219|net.8.mp3|rock
& 212|net.1.mp3|metal
& 215|net.4.mp3|slow jam
& 213|net.2.mp3|techno

Now in the next step I want to use the values of the selected listbox that correlate with the loaded array.

onChange = function ()
{ if (combobox.getValue() == “The 1st value of the array”)
{screen.loadSound(“The 2nd value of the array”, true);}

Well, how did you put the data in the listbox exactly?

loader = new LoadVars();
loader.onLoad = function(){
loader.load (thefile.asp)

I am at home now and I cant rember the code I used, but the list box is useing a loop function that reads the numer of strings and labels them song1,song2,song3 ect…

This won’t put it in the listbox… :slight_smile:

var list = new Array();
loader = new LoadVars();
loader.onLoad = function() {

var n = 1;
for (var i in loader) {
trace(i+": “+this*);
// split the label from the data
var list = this*.split(”|");
// fill the combobox
combobox.addItem("Read profile “+n+” "+list[0], [list[1]]);
n = n+1;
}
};
loader.load(“http://www.file.asp”);

Hope this helps.

:rambo:

by using “&” in the variable file, the loadvars object is interpreting it as a list of variables in name value pairs. but there are no “=” so essentailly, it’s a list of variable names, with no values attached.

you could use “=” in the file.asp, or, i think your existing code will work if you reference the variable name rather than its value (since it has no value).

note where i’ve written “i” instead of “this*”:


loader = new LoadVars();
loader.onLoad = function() {
   var list,n;
   for (var i in loader) {
      n++;
      list = i.split("|");
      combobox.addItem("Read profile "+n+" "+list[0], list[1]);
   }
};
loader.load("http://www.file.asp");

are you doing anything with list[2]? you seem to have three components to each variable.

i might also add that it’s a little unorthodox to be splitting the variable name. it’s only flashes permissive casting that lets you get away with that.

note where i’ve written “i” instead of “this*”:
I don’t understand, Supra… :cyclops: :q:

All is working well except the last part of my original code.

onChange = function ()
{ if (combobox.getValue() == “The 1st value of the array”)
{screen.loadSound(“The 2nd value of the array”, true);}

When I try something like;

onChange = function ()
{ if (combobox.getValue() == “list[1]”)
{screen.loadSound(“list[1]”, true);}

I get a error message saying

Error opening URL “list[1]”.

It should not say list[1], it should give the 2nd value of the array.

The loadSound command is asking for a url. How do I show it the array.
:pirate:

waffe - no quotes

ily - with this (moderately whacked, but hey, if it ain’t broke…) method of importing data it’s the names of the variables that contain the data, as opposed to their values. thus in a for(i in this) loop, i contains the relevant data as opposed to this*.

is that what you were getting at?

If i contains the relevant data as opposed to this*, then how do I plug in the their values into the loadSound command?

onChange = function ()
{ if (combobox.getValue() == “i[1]”) ???
{screen.loadSound(“i[1]”, true);} ???

If I do not use quotes in
{screen.loadSound(i[1], true);}

The loadSound command read nothing for the url field.

3 days of questions, tutorials and the answer mine!

The answer to my last question is
onChange = function () { screen.loadSound(combobox.getSelectedItem().data, true);};

The whole time I was not using combobox in my code.:x

Thank you kirupa.com for all your support.

Bill