PDA

View Full Version : XML population Listbox/Tree


Faust
07-08-2004, 09:01 PM
okay i know i am asking for help that has been thrown around alot on this forum and i have probably read more then 75% of them in the past 2 days and yet i can't find anything that really solves the problem:

XML FILE:

<?xml version="1.0" encoding="utf-8" ?>
<xmlsonglist>
<totalSongs number="3" />

<song>
<Title>Bartender</Title>
<Artist>Rehab</Artist>
<Album>N/A</Album>
<Genre>Rock</Genre>
<Path>Http://studentwebs.colstate.edu/huot_justin/sound/bartender.mp3</Path>
</song>

<song>
<Title>Daffy Duck</Title>
<Artist>N/A</Artist>
<Album>N/A</Album>
<Genre>Comedy</Genre>
<Path>Http://studentwebs.colstate.edu/huot_justin/sound/dd.mp3</Path>
</song>

<song>
<Title>Souther Hospitality</Title>
<Artist>Ludicris</Artist>
<Album>Chicken&Beer</Album>
<Genre>Rap</Genre>
<Path>Http://studentwebs.colstate.edu/huot_justin/sound/southern_hosp.mp3</Path>
</song>

</xmlsonglist>


XML LOAD AND PARSER

PLXML = new XML();
PLXML.ignoreWhite = true;
PLXML.load("http://studentwebs.colstate.edu/huot_justin/Mp3_Player/Faust.xml");
PLXML.onLoad = xmlLoaded;
function xmlLoaded(success) {
if (success) {
trace("XML file is loaded");
parseXML();
} else {
trace("*** XML FILE DID NOT LOAD ***");
}
}
// makes Arrays
aryItem = new Array("Title", "Artist", "Album", "Genre", "Path");
aryTitle = new Array();
aryArtist = new Array();
aryAlbum = new Array();
aryGenre = new Array();
aryPath = new Array();
// Parse the XML
function parseXML() {
totalSongs = PLXML.firstChild.firstChild.attributes.number;
//trace("Number of songs: " + totalSongs);
for (n=0; n<PLXML.firstChild.childNodes.length; n++) {
//trace(PLXML.firstChild.childNodes.length);
if (PLXML.firstChild.childNodes[n].nodeName == "song") {
//trace(PLXML.firstChild.childNodes[n].nodeName);
for (i=0; i<PLXML.firstChild.childNodes[n].childNodes.length; i++) {
//trace(PLXML.firstChild.childNodes[n].childNodes[i].firstChild.nodeValue);
if (PLXML.firstChild.childNodes[n].childNodes[i].nodeName == aryItem[i]) {
this["ary"+aryItem[i]].push(PLXML.firstChild.childNodes[n].childNodes[i].firstChild.nodeValue);
}
}
}
}
populateListBox();
}
function populateListBox() {
trace("Funciton PopulateListBox running...");
for (j=0; j<aryArtist.length; j++) {
trace(aryArtist[j].toString());
file = aryArtist[j]+" : "+aryTitle[j];
trace(file.toString());

//Listbox is lstPlayList1
_root.lstPlayList1.addItem(file, aryPath[j].toString());
}
trace("... PopulateListBox is Closing");
}



the majority of the parser came from a post on here and that works great. as you can see in the output:


XML file is loaded

Funciton PopulateListBox running...
Rehab
Rehab : Bartender
N/A
N/A : Daffy Duck
Ludicris
Ludicris : Souther Hospitality
... PopulateListBox is Closing



so if this is in the array why won't it populate the listbox???

for (j=0; j<aryArtist.length; j++) {
trace(aryArtist[j].toString());
file = aryArtist[j]+" : "+aryTitle[j];
trace(file.toString());
_root.lstPlayList1.addItem(file, aryPath[j].toString());
}

yet when the movie runs nothing is in the Listbox, so i guess my question is if the data in the array is outputed then why won't it add the data to the listbox?

Thanks in advance, :D
Faust

CyanBlue
07-08-2004, 09:21 PM
Howdy... :)

I just copied your ActionScript and created one ListBox on the stage with its instance name set to lstPlayList1... Guess what... It works just fine... :)

Why don't you do the same thing that I did on the new file and see if that works???

Faust
07-08-2004, 09:30 PM
LOL the one thing i didn't try! somehow the listbox became a symbol??? oh well

Side question: why wound't the symbol Listbox not load the data but the instance ListBox does? does a component lose its properties when its been converted to a symbol?

sorry for the questions and thanks again,
Faust

lol you happen to be helping me alot heh

CyanBlue
07-08-2004, 09:40 PM
Um... I am not sure what you mean by the 'symbol', but if you made a movieClip out of the ListBox component, then the path becomes different, and if you made a graphic, the path becomes invalid... I think that's what you are asking... :)

Faust
07-08-2004, 09:45 PM
yes!

god its going to take me forever to figure actionscripting out! :(


since you seem to be so helpful what function do you use to grab the value set to a listbox? i keep getting [object Object] or undefined? lol this isn't as similar to vb as i thought :( :( :(

CyanBlue
07-08-2004, 09:47 PM
Well... It isn't VB, and it ain't easy if you ask me... I am not even near the place wher I can figure out what ActionScript is... ;)

Open up the Flash manual(F1) and look for 'FListBox.setChangeHandler' for the example... That one should help you get going... ;)

Faust
07-08-2004, 09:49 PM
err sorry school won't let us see manuals ( cheap asses ) so we got to search web for the answers

poor college students heh

CyanBlue
07-08-2004, 09:51 PM
Uh, what??? I don't know WHY they don't want you to see the manual, but are they okay with asking to somebody else??? :D

Search for the 'setChangeHandler' in the forum and Macromedia's site instead then... :)

Faust
07-08-2004, 11:07 PM
lol yeah i got about 200$ (us) in textbooks for this damn class and they couldn't answer some of the quesitons i am having so they better damn allow it!!!!! HEH

Faust okies? thanks

Faust
07-09-2004, 12:20 AM
One more question: (probably not though lol)


on (press){

uncommented the song plays
//temp_song = "http://studentwebs.colstate.edu/huot_justin/sound/southern_hosp.mp3";

This function isn't even being called so i am betting money this is the problem?
ClickSelect = function()
{
temp_song = lstPlayList1.selectedItem().data.Path;
trace (temp_song);
}

this._parent.lstPlayList1.setChangeHandler("ClickSelect");

}

on (release) {



//Load Streaming mp3 behavior
if(_global.Behaviors == null)_global.Behaviors = {};
if(_global.Behaviors.Sound == null)_global.Behaviors.Sound = {};
if(typeof this.createEmptyMovieClip == 'undefined'){
this._parent.createEmptyMovieClip('BS_TempSong',ne w Date().getTime()-(Math.floor((new Date().getTime()) /10000)*10000) );
_global.Behaviors.Sound.TempSong = new Sound(this._parent.BS_TempSong);
} else {
this.createEmptyMovieClip('_TempSong_',new Date().getTime()-(Math.floor((new Date().getTime()) /10000)*10000) );
_global.Behaviors.Sound.TempSong = new Sound(this.BS_TempSong);
}

_global.Behaviors.Sound.TempSong.loadSound(temp_so ng,true);
}



thanks in advance again!
heh

tg
07-09-2004, 03:08 PM
the electronic manual.... that's installed on your computer when flash is installed. hit 'F1' that should bring it up. or open up the 'reference' panel.

CyanBlue
07-09-2004, 03:20 PM
Shhhh... That'll be called cheating... :p

tg
07-09-2004, 03:37 PM
the game is just not fun anymore unless everyone is cheating as vigorously as possible all the time.