View Full Version : Question about using list component

12-27-2006, 04:26 PM

I've actually never used components before so having a little trouble figuring out how to do this, although I would think it would be simple?

Basically there is a list component that holds a list of gallery names.
The list component display a list of gallery names, gallery1 - gallery7
The only thing I need to figure out is that I want to call a function whenever each list item is clicked. Just don't know how...

Thanks for any help

// The following example discovers the number of visible items in a list:
var rowCount = my_list.rowCount;

// The following example removes a partial row at the bottom of a list, if there is one:
my_list.rowCount = my_list.rowCount;

// The following example resizes the list using the setSize() method and then sets a row count of 8 items:
my_list.addItem({data:"gallery1", label:"gallery1"});
my_list.addItem({data:"gallery2", label:"gallery2"});
my_list.addItem({data:"gallery3", label:"gallery3"});
my_list.addItem({data:"gallery4", label:"gallery4"});
my_list.addItem({data:"gallery5", label:"gallery5"});
my_list.addItem({data:"gallery6", label:"gallery6"});
my_list.addItem({data:"gallery7", label:"gallery7"});

my_list.setSize(130, 30);
my_list.rowCount = 7;
my_list.hScrollPolicy = "off";
trace("my_list has " + my_list.rowCount + " rows.");

// set the row height
my_list.rowHeight = 20;

// custom look 'n' feel...
my_list.backgroundColor = "0x2c2c2c";
my_list.borderStyle = "none";
my_list.color = "0x94CE00";
my_list.embedFonts = "true";
my_list.fontFamily = "FFF Star";
my_list.fontWeight = "normal";
my_list.fontSize = "8";
my_list.textRollOverColor = "0x777777";
my_list.textSelectedColor = "0x898888";
my_list.rollOverColor = "0x2c2c2c";
my_list.selectionColor = "0x2c2c2c";

12-27-2006, 05:56 PM
ok, moved to components, thankyou, i just figured since it was being controlled via actionscript...

anyway here's the answer for anyone else that needs to do this...

var listHandler:Object = new Object();
listHandler.change = function(evt:Object) {
switch (evt.target.selectedItem.data) {
case "gallery1" :
trace("1"); break;
case "gallery2" :
trace("2"); break;
case "gallery3" :
trace("3"); break;
default :
trace("unhandled event: "+evt.target.selectedItem.data);

my_list.addEventListener("change", listHandler);

12-27-2006, 06:13 PM
should be able to do it this way too:

var listHandler:Object = new Object();
listHandler.change = function(evt:Object) {
_root.ssp.loadAlbum(evt.target.selectedItem.label) ;

my_list.addEventListener("change", listHandler);