# Listbox, ScrollPane, and Textbox

**URL:** <https://forum.kirupa.com/t/listbox-scrollpane-and-textbox/27502>\
**Category:** flash\
**Created:** [August 3, 2003, 8:23am UTC](https://forum.kirupa.com/t/listbox-scrollpane-and-textbox/27502 "2003-08-03T08:23:26Z")\
**Posts on this page:** 20\
**Page:** 1

<div class="post-metadata">

**Author:** ![JK87](https://avatars.discourse-cdn.com/v4/letter/j/0ea827/32.png) [@JK87](https://forum.kirupa.com/u/JK87)\
**Post date:** [August 3, 2003, 8:23am UTC](https://forum.kirupa.com/t/listbox-scrollpane-and-textbox/27502/1 "2003-08-03T08:23:26Z")

</div>

I have a little question:

A listbox with the instance name “list”, a dynamic textbox with the instance name “infotb”, and a scrollpane with the instance name “imgsp”.

Now, using this AS:  
[AS]var myLoadVars = new LoadVars() ;  
myLoadVars.onLoad = function(success) {  
if (success) {  
var str = unescape(this), infolist = str.substr(0, str.length-1).split("  
"), index ;  
for (index = 0 ; index \< infolist.length ; index++) {  
list.addItem(infolist[index]) ;  
list.sortItemsBy(fieldName, asc) ;  
}  
} else {  
trace(“Error loading contents!”) ;  
}  
} ;

myLoadVars.load(“infolist.txt”) ;  
ASSetPropFlags(myLoadVars, “onLoad”, 1) ;[/AS]  
which Kax posted in a thread some time ago, I am able to use a textfile to add items to the listbox (each line of text in the text file is a new item in the listbox).

However, I am unsure of what AS would be required so that two other values are read from the text file for each item. Those two values would be i) the name of an image [for the scrollpane imgsp] and ii) the name of a textfile [to be loaded into the dynamic textbox infotb].

e.g. One line of the text file could be:  
JK87 [myimg.jpg, mytext.txt]

Or similar. When Flash reads the text file, it adds the item JK87 to the listbox and takes those two file names and if that item of the listbox (JK87) is selected, tells the scrollpane to display myimg.jpg and tells the dynamic textbox to display the text in mytext.txt

Could somebody please help me? Pretty please?(-:

Thanks for any and all help,  
JK.

---

<div class="post-metadata">

**Author:** ![system](https://canada1.discourse-cdn.com/flex011/uploads/kirupa/original/3X/6/2/621e5c11736f46532526e61be85940af4230f3e5.png) [@system](https://forum.kirupa.com/u/system)\
**Post date:** [August 3, 2003, 10:32am UTC](https://forum.kirupa.com/t/listbox-scrollpane-and-textbox/27502/2 "2003-08-03T10:32:40Z")

</div>

Wouldnt be better to use XML in that case?  
Just a guess  
:-\

---

<div class="post-metadata">

**Author:** ![system](https://canada1.discourse-cdn.com/flex011/uploads/kirupa/original/3X/6/2/621e5c11736f46532526e61be85940af4230f3e5.png) [@system](https://forum.kirupa.com/u/system)\
**Post date:** [August 3, 2003, 10:49am UTC](https://forum.kirupa.com/t/listbox-scrollpane-and-textbox/27502/3 "2003-08-03T10:49:06Z")

</div>

I have absolutely no idea how to use XML lol. Or mySQL (with Flash or PHP) for that matter. I read the introduction tutorial for XML but it didn’t really sink in.

Could you give me an example of what I would need to use (the AS and the XML) in order to do this using XML please? :).

---

<div class="post-metadata">

**Author:** ![system](https://canada1.discourse-cdn.com/flex011/uploads/kirupa/original/3X/6/2/621e5c11736f46532526e61be85940af4230f3e5.png) [@system](https://forum.kirupa.com/u/system)\
**Post date:** [August 3, 2003, 11:06am UTC](https://forum.kirupa.com/t/listbox-scrollpane-and-textbox/27502/4 "2003-08-03T11:06:43Z")

</div>

Man i suck at XML. Maybe someone more experienced can help you with that.  
🙂

---

<div class="post-metadata">

**Author:** ![system](https://canada1.discourse-cdn.com/flex011/uploads/kirupa/original/3X/6/2/621e5c11736f46532526e61be85940af4230f3e5.png) [@system](https://forum.kirupa.com/u/system)\
**Post date:** [August 3, 2003, 11:11am UTC](https://forum.kirupa.com/t/listbox-scrollpane-and-textbox/27502/5 "2003-08-03T11:11:16Z")

</div>

Heh ok thx for the help so far :).

_looks around for somebody who is more experienced with combining XML and Flash(-:_

---

<div class="post-metadata">

**Author:** ![system](https://canada1.discourse-cdn.com/flex011/uploads/kirupa/original/3X/6/2/621e5c11736f46532526e61be85940af4230f3e5.png) [@system](https://forum.kirupa.com/u/system)\
**Post date:** [August 3, 2003, 11:44am UTC](https://forum.kirupa.com/t/listbox-scrollpane-and-textbox/27502/6 "2003-08-03T11:44:18Z")

</div>

Just to get things rolling on the XML side of things, I looked through the tutorials again and came up with this XML so far:

```php

<USERS>
	<JK87 IMAGE="jk87.jpg" NAME="Jonathan King" AGE="15" />
	<Two IMAGE="two.jpg" NAME="T W O" AGE="16" />
</USERS>

```

Bear in mind, I don’t know the most efficient way of using XML but I thought that if I created a node for each listbox item, that might be a sensible way of doing things.

Therefore in the XML above, the listbox items would be JK87 and Two. And then the image displayed would be jk87.jpg or two.jpg depending on which listbox item is selected. And the extra information (name and age) would be entered into the textbox.

Could somebody please check this and explain to me how on Earth I get Flash to use the XML in the way I described?

Thanks soooo much,  
JK :beam:.

---

<div class="post-metadata">

**Author:** ![system](https://canada1.discourse-cdn.com/flex011/uploads/kirupa/original/3X/6/2/621e5c11736f46532526e61be85940af4230f3e5.png) [@system](https://forum.kirupa.com/u/system)\
**Post date:** [August 3, 2003, 11:46am UTC](https://forum.kirupa.com/t/listbox-scrollpane-and-textbox/27502/7 "2003-08-03T11:46:24Z")

</div>

Hey JK, can I take a look at the fla and the txt file?

---

<div class="post-metadata">

**Author:** ![system](https://canada1.discourse-cdn.com/flex011/uploads/kirupa/original/3X/6/2/621e5c11736f46532526e61be85940af4230f3e5.png) [@system](https://forum.kirupa.com/u/system)\
**Post date:** [August 3, 2003, 11:55am UTC](https://forum.kirupa.com/t/listbox-scrollpane-and-textbox/27502/8 "2003-08-03T11:55:13Z")

</div>

Sure but there isn’t an actual text file atm… In the .fla all there is a textbox, a listbox, a scrollpane and some AS. But here you go 🙂 : [download link removed].

I imagine that the only external file required would be the .xml file with the information I posted above (the XML code).

[note: The current AS in the .fla is designed to work with a .txt file called infolist.txt and it basically adds each line of text in the text file as a new listbox item. I guess that would need to change when XML is used]

Thanks,  
JK.

---

<div class="post-metadata">

**Author:** ![system](https://canada1.discourse-cdn.com/flex011/uploads/kirupa/original/3X/6/2/621e5c11736f46532526e61be85940af4230f3e5.png) [@system](https://forum.kirupa.com/u/system)\
**Post date:** [August 3, 2003, 1:33pm UTC](https://forum.kirupa.com/t/listbox-scrollpane-and-textbox/27502/9 "2003-08-03T13:33:45Z")

</div>

I think got a way around this… i used a different approach than Kax. I used 2 txt files, one holding the listbox itens and another with the sub data info.  
Heres the code i used:[AS]var loadText = new LoadVars();  
loadText.load(“infolist.txt”);  
loadText.onLoad = function(success) {  
if (success) {  
var listArray = loadText.listdata.split(’,’), i; //split the content of txt file into an array  
for (i=0; i\<listArray.length; i++) {  
list.addItem(listArray\*); //pass the values stored in the array to the listbox  
}  
} else {  
list.addItem(“Error loading contents!”);  
}  
};  
list.setChangeHandler(“myHandler”);  
function myHandler(component) {  
var which = list.getSelectedItem().label;//set which item is selected  
var subData = new LoadVars();  
subData.load(“sublist.txt”);  
subData.onLoad = function(success) {  
if (success) {  
contenttb.text = this[which];//search the txt file for the correspondent info  
imgsp.loadScrollContent(which+".jpg");//load correspondent image  
} else {  
contenttb.text = “Error loading sub data!”;  
}  
};  
}  
[/AS]  
Hope it helps.

---

<div class="post-metadata">

**Author:** ![system](https://canada1.discourse-cdn.com/flex011/uploads/kirupa/original/3X/6/2/621e5c11736f46532526e61be85940af4230f3e5.png) [@system](https://forum.kirupa.com/u/system)\
**Post date:** [August 3, 2003, 1:47pm UTC](https://forum.kirupa.com/t/listbox-scrollpane-and-textbox/27502/10 "2003-08-03T13:47:41Z")

</div>

_Does a little dance_

All hail claudio, KING of ActionScript :beam: :beam:.  
Thankyou soooo much claudio :).

Oh and btw, I love the images you used for testing :thumb: ;).

---

<div class="post-metadata">

**Author:** ![system](https://canada1.discourse-cdn.com/flex011/uploads/kirupa/original/3X/6/2/621e5c11736f46532526e61be85940af4230f3e5.png) [@system](https://forum.kirupa.com/u/system)\
**Post date:** [August 3, 2003, 1:49pm UTC](https://forum.kirupa.com/t/listbox-scrollpane-and-textbox/27502/11 "2003-08-03T13:49:20Z")

</div>

Ahhh glad i could help you =)  
And those images were reallly crap 😛 i was too lazy to search google…

---

<div class="post-metadata">

**Author:** ![system](https://canada1.discourse-cdn.com/flex011/uploads/kirupa/original/3X/6/2/621e5c11736f46532526e61be85940af4230f3e5.png) [@system](https://forum.kirupa.com/u/system)\
**Post date:** [August 3, 2003, 2:54pm UTC](https://forum.kirupa.com/t/listbox-scrollpane-and-textbox/27502/12 "2003-08-03T14:54:29Z")

</div>

Just in case you want the listbox options to be displayed in alphabetic order, use:  
[AS]var loadText = new LoadVars();  
loadText.load(“infolist.txt”);  
loadText.onLoad = function(success) {  
if (success) {  
var listArray = loadText.listdata.split(’,’), i; //split the content of txt file into an array  
listArray.sort();//sort itens in alphabetic order (descend)  
for (i=0; i\<listArray.length; i++) {  
list.addItem(listArray\*); //pass the values stored in the array to the listbox  
}  
} else {  
list.addItem(“Error loading contents!”);  
}  
};  
list.setChangeHandler(“myHandler”);  
function myHandler(component) {  
var which = list.getSelectedItem().label;//set which item is selected  
var subData = new LoadVars();  
subData.load(“sublist.txt”);  
subData.onLoad = function(success) {  
if (success) {  
contenttb.text = this[which];//search the txt file for the correspondent info  
imgsp.loadScrollContent(which+".jpg");//load correspondent image  
} else {  
contenttb.text = “Error loading sub data!”;  
}  
};  
}[/AS]

---

<div class="post-metadata">

**Author:** ![system](https://canada1.discourse-cdn.com/flex011/uploads/kirupa/original/3X/6/2/621e5c11736f46532526e61be85940af4230f3e5.png) [@system](https://forum.kirupa.com/u/system)\
**Post date:** [August 3, 2003, 3:13pm UTC](https://forum.kirupa.com/t/listbox-scrollpane-and-textbox/27502/13 "2003-08-03T15:13:17Z")

</div>

Thanks :thumb:. Ooh btw, I’ve been trying to do it with XML as well (just for future reference) and I’m so darn close lol. Your way is almost certainly easier for a small-scale operation like the one that I am doing atm but I intend to do it on a much larger scale in the future, which means I need to try it with XML.

So far, I’ve worked out how to display the following:  
[AS]  
//Number of users:  
myXML.firstChild.childNodes.length  
//Name of user (replace n with a node number):  
myXML.firstChild.childNodes[n].nodeName  
//Data of user (replace i with a node number):  
myXML.firstChild.childNodes\*.childNodes[0].nodeValue  
//Display data in contenttb (replace i with a node number):  
contenttb.text = myXML.firstChild.childNodes\*.childNodes[0].nodeValue[/AS]

When the XML data is specified in Flash by using:  
[AS]myXML = new XML( ‘\<USERS\>\<JK87\>Nick: JK87  
Name: Jonathan King  
Age: 15\</JK87\>’ +  
‘\<Two\>Nick: 2  
Name: 2  
Age: 2\</Two\>’ +  
‘\<Three\>Nick: 3  
Name: 3  
Age: 3\</Three\>\</USERS\>’) ;[/AS]

---

<div class="post-metadata">

**Author:** ![system](https://canada1.discourse-cdn.com/flex011/uploads/kirupa/original/3X/6/2/621e5c11736f46532526e61be85940af4230f3e5.png) [@system](https://forum.kirupa.com/u/system)\
**Post date:** [August 3, 2003, 3:19pm UTC](https://forum.kirupa.com/t/listbox-scrollpane-and-textbox/27502/14 "2003-08-03T15:19:54Z")

</div>

I would definetely help you if i knew XML. 🙂  
I guess its time for me to learn that…  
:beam:

---

<div class="post-metadata">

**Author:** ![system](https://canada1.discourse-cdn.com/flex011/uploads/kirupa/original/3X/6/2/621e5c11736f46532526e61be85940af4230f3e5.png) [@system](https://forum.kirupa.com/u/system)\
**Post date:** [August 3, 2003, 3:26pm UTC](https://forum.kirupa.com/t/listbox-scrollpane-and-textbox/27502/15 "2003-08-03T15:26:23Z")

</div>

Heh yeah, me too :). No time like the present! ;).

I’ve got the user nicks displaying in the listbox now. I just have to work out the next bit regarding how each selection in the listbox affects what is displayed in the textbox.

Man… it’s a lot of work when you have no idea what you’re doing (-:.

---

<div class="post-metadata">

**Author:** ![system](https://canada1.discourse-cdn.com/flex011/uploads/kirupa/original/3X/6/2/621e5c11736f46532526e61be85940af4230f3e5.png) [@system](https://forum.kirupa.com/u/system)\
**Post date:** [August 3, 2003, 3:50pm UTC](https://forum.kirupa.com/t/listbox-scrollpane-and-textbox/27502/16 "2003-08-03T15:50:43Z")

</div>

Yea i know the feeling 🙂  
Good luck for you… let me see the final result.

---

<div class="post-metadata">

**Author:** ![system](https://canada1.discourse-cdn.com/flex011/uploads/kirupa/original/3X/6/2/621e5c11736f46532526e61be85940af4230f3e5.png) [@system](https://forum.kirupa.com/u/system)\
**Post date:** [August 3, 2003, 4:03pm UTC](https://forum.kirupa.com/t/listbox-scrollpane-and-textbox/27502/17 "2003-08-03T16:03:02Z")

</div>

Well, I’ve got guests coming over tonight so I’m probably going to have to stop until tomorrow. So far I have the names displaying in the listbox (haven’t set an error thing in-case they can’t load) but I just can’t work out how to get the textbox to work in coordindation with what is selected in the listbox.

I used trace to test “list.getSelectedItem().label” and it returned “undefined”. I would expect that this is being caused by the way I told Flash to add the listbox items (users). I can’t really see a way round it right now - I tried using index values for the listbox items; still “undefined”. I even tried changing what is entered so that each item had a data value (“list.getSelectedItem().data” to see what data you added) as well as its label but it still came up as “undefined”.

I’m lost for now but I will have another whack tomorrow. If you have any questions about what I have done so far, just post here and I’ll try and pop back when our guests aren’t looking :).

Here’s the .fla so far: [http://www.modulus.plus.com/87xml.fla](http://www.modulus.plus.com/87xml.fla)  
And the XML is actually set using AS in the .fla so there are no external documents for the moment (I was having problems using an external .xml file to store the XML data).

Thanks for any help you can offer,  
JK.

---

<div class="post-metadata">

**Author:** ![system](https://canada1.discourse-cdn.com/flex011/uploads/kirupa/original/3X/6/2/621e5c11736f46532526e61be85940af4230f3e5.png) [@system](https://forum.kirupa.com/u/system)\
**Post date:** [August 3, 2003, 11:18pm UTC](https://forum.kirupa.com/t/listbox-scrollpane-and-textbox/27502/18 "2003-08-03T23:18:01Z")

</div>

Well, it’s 00:15 am, our guests have gone and I have absolutely no idea how to get the last bit of this to work lol. If anybody could help me out, that would be great :beam:.

Thanks,  
JK.

---

<div class="post-metadata">

**Author:** ![system](https://canada1.discourse-cdn.com/flex011/uploads/kirupa/original/3X/6/2/621e5c11736f46532526e61be85940af4230f3e5.png) [@system](https://forum.kirupa.com/u/system)\
**Post date:** [August 3, 2003, 11:36pm UTC](https://forum.kirupa.com/t/listbox-scrollpane-and-textbox/27502/19 "2003-08-03T23:36:48Z")

</div>

Also, claudio, how would I change the following so that if no image file was found, it displays a default image (e.g . noimage.jpg) ?  
[note: this is from the .fla you created which uses textfiles rather than XML]  
[AS]imgsp.loadScrollContent(which+".jpg");//load corresponding image[/AS]

I’m not sure as to how you check if which+".jpg" exists. If somebody can explain that, it would be great because then all that would be required would be along the lines of:

```auto
if (insert check if which+.jpg exists == true){
imgsp.loadScrollContent(which+".jpg");
}else{
imgsp.loadScrollContent("noimage.jpg");
}
 

```

Thanks again,  
JK.

---

<div class="post-metadata">

**Author:** ![system](https://canada1.discourse-cdn.com/flex011/uploads/kirupa/original/3X/6/2/621e5c11736f46532526e61be85940af4230f3e5.png) [@system](https://forum.kirupa.com/u/system)\
**Post date:** [August 4, 2003, 8:52am UTC](https://forum.kirupa.com/t/listbox-scrollpane-and-textbox/27502/20 "2003-08-04T08:52:03Z")

</div>

Hmmm… after a little more rigorous searching, I managed to find a thread in which my question about how to check whether a file is present is pretty much answered. For those of you who’re interested:  
[http://www.kirupaforum.com/forums/showthread.php?s=&threadid=9872&highlight=check+if+a+file+exists](http://www.kirupaforum.com/forums/showthread.php?s=&threadid=9872&highlight=check+if+a+file+exists)
